This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/elektronLogging/clsfnTaskDistOverheadLogger.go

57 lines
1.3 KiB
Go
Raw Normal View History

2019-11-13 11:19:04 -05:00
package elektronLogging
import (
2019-11-20 13:33:46 -05:00
"os"
2019-11-21 15:26:57 -05:00
"path/filepath"
"strings"
log "github.com/sirupsen/logrus"
2019-11-13 11:19:04 -05:00
)
2019-11-21 15:26:57 -05:00
type ClsfnTaskDistrOverheadLogger struct {
2019-11-13 11:19:04 -05:00
LoggerImpl
}
2019-11-21 15:26:57 -05:00
func NewClsfnTaskDistrOverheadLogger(logType int, prefix string) *ClsfnTaskDistrOverheadLogger {
cLog := &ClsfnTaskDistrOverheadLogger{}
2019-11-13 11:19:04 -05:00
cLog.Type = logType
cLog.CreateLogFile(prefix)
2019-11-13 11:19:04 -05:00
return cLog
}
2019-11-21 18:04:59 -05:00
func (cLog ClsfnTaskDistrOverheadLogger) Log(logType int, level log.Level, logData log.Fields, message string) {
if config.TaskDistrConfig.Enabled {
if cLog.Type == logType {
2019-11-13 11:19:04 -05:00
logger.SetLevel(level)
2019-11-20 13:33:46 -05:00
if cLog.AllowOnConsole {
logger.SetOutput(os.Stdout)
logger.WithFields(logData).Println(message)
}
logger.SetOutput(cLog.LogFile)
2019-11-20 13:33:46 -05:00
logger.WithFields(logData).Println(message)
}
if cLog.next != nil {
cLog.next.Log(logType, level, logData, message)
}
2019-11-13 11:19:04 -05:00
}
}
func (cLog *ClsfnTaskDistrOverheadLogger) CreateLogFile(prefix string) {
2019-11-13 11:19:04 -05:00
if config.TaskDistrConfig.Enabled {
filename := strings.Join([]string{prefix, config.TaskDistrConfig.FilenameExtension}, "")
dirName := logDir.getDirName()
if dirName != "" {
if logFile, err := os.Create(filepath.Join(dirName, filename)); err != nil {
log.Fatal("Unable to create logFile: ", err)
} else {
cLog.LogFile = logFile
cLog.AllowOnConsole = config.TaskDistrConfig.AllowOnConsole
}
2019-11-21 18:04:59 -05:00
}
2019-11-13 11:19:04 -05:00
}
}