github.com/space0122/mattermost-server@v5.11.1+incompatible/utils/logger.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package utils
     5  
     6  import (
     7  	"path/filepath"
     8  	"strings"
     9  
    10  	"github.com/mattermost/mattermost-server/mlog"
    11  	"github.com/mattermost/mattermost-server/model"
    12  	"github.com/mattermost/mattermost-server/utils/fileutils"
    13  )
    14  
    15  const (
    16  	LOG_ROTATE_SIZE = 10000
    17  	LOG_FILENAME    = "mattermost.log"
    18  )
    19  
    20  func MloggerConfigFromLoggerConfig(s *model.LogSettings) *mlog.LoggerConfiguration {
    21  	return &mlog.LoggerConfiguration{
    22  		EnableConsole: *s.EnableConsole,
    23  		ConsoleJson:   *s.ConsoleJson,
    24  		ConsoleLevel:  strings.ToLower(*s.ConsoleLevel),
    25  		EnableFile:    *s.EnableFile,
    26  		FileJson:      *s.FileJson,
    27  		FileLevel:     strings.ToLower(*s.FileLevel),
    28  		FileLocation:  GetLogFileLocation(*s.FileLocation),
    29  	}
    30  }
    31  
    32  func GetLogFileLocation(fileLocation string) string {
    33  	if fileLocation == "" {
    34  		fileLocation, _ = fileutils.FindDir("logs")
    35  	}
    36  
    37  	return filepath.Join(fileLocation, LOG_FILENAME)
    38  }
    39  
    40  // DON'T USE THIS Modify the level on the app logger
    41  func DisableDebugLogForTest() {
    42  	mlog.GloballyDisableDebugLogForTest()
    43  }
    44  
    45  // DON'T USE THIS Modify the level on the app logger
    46  func EnableDebugLogForTest() {
    47  	mlog.GloballyEnableDebugLogForTest()
    48  }