mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* MM-34787: Add colored output for non JSON console logs https://mattermost.atlassian.net/browse/MM-34787 ```release-note A new field EnableColor is added to LogSettings and NotificationLogSettings. Non-JSON console logs will now be colored if that field is set to true. ``` * Trigger CI
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package utils
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
"github.com/mattermost/mattermost-server/v5/shared/mlog"
|
|
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
|
|
)
|
|
|
|
const (
|
|
LogRotateSize = 10000
|
|
LogFilename = "mattermost.log"
|
|
LogNotificationFilename = "notifications.log"
|
|
)
|
|
|
|
type fileLocationFunc func(string) string
|
|
|
|
func MloggerConfigFromLoggerConfig(s *model.LogSettings, getFileFunc fileLocationFunc) *mlog.LoggerConfiguration {
|
|
return &mlog.LoggerConfiguration{
|
|
EnableConsole: *s.EnableConsole,
|
|
ConsoleJson: *s.ConsoleJson,
|
|
ConsoleLevel: strings.ToLower(*s.ConsoleLevel),
|
|
EnableFile: *s.EnableFile,
|
|
FileJson: *s.FileJson,
|
|
FileLevel: strings.ToLower(*s.FileLevel),
|
|
FileLocation: getFileFunc(*s.FileLocation),
|
|
EnableColor: *s.EnableColor,
|
|
}
|
|
}
|
|
|
|
func GetLogFileLocation(fileLocation string) string {
|
|
if fileLocation == "" {
|
|
fileLocation, _ = fileutils.FindDir("logs")
|
|
}
|
|
|
|
return filepath.Join(fileLocation, LogFilename)
|
|
}
|
|
|
|
func GetNotificationsLogFileLocation(fileLocation string) string {
|
|
if fileLocation == "" {
|
|
fileLocation, _ = fileutils.FindDir("logs")
|
|
}
|
|
|
|
return filepath.Join(fileLocation, LogNotificationFilename)
|
|
}
|
|
|
|
func GetLogSettingsFromNotificationsLogSettings(notificationLogSettings *model.NotificationLogSettings) *model.LogSettings {
|
|
return &model.LogSettings{
|
|
ConsoleJson: notificationLogSettings.ConsoleJson,
|
|
ConsoleLevel: notificationLogSettings.ConsoleLevel,
|
|
EnableConsole: notificationLogSettings.EnableConsole,
|
|
EnableFile: notificationLogSettings.EnableFile,
|
|
FileJson: notificationLogSettings.FileJson,
|
|
FileLevel: notificationLogSettings.FileLevel,
|
|
FileLocation: notificationLogSettings.FileLocation,
|
|
AdvancedLoggingConfig: notificationLogSettings.AdvancedLoggingConfig,
|
|
EnableColor: notificationLogSettings.EnableColor,
|
|
}
|
|
}
|
|
|
|
// DON'T USE THIS Modify the level on the app logger
|
|
func DisableDebugLogForTest() {
|
|
mlog.GloballyDisableDebugLogForTest()
|
|
}
|
|
|
|
// DON'T USE THIS Modify the level on the app logger
|
|
func EnableDebugLogForTest() {
|
|
mlog.GloballyEnableDebugLogForTest()
|
|
}
|