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/loggerChain.go

55 lines
1.1 KiB
Go
Raw Normal View History

2019-11-13 11:19:04 -05:00
package elektronLogging
import (
log "github.com/sirupsen/logrus"
"os"
2019-11-13 11:19:04 -05:00
)
type Logger interface {
SetNext(logType Logger)
Log(logType int, level log.Level, message string)
Logf(logType int, level log.Level, msgFmtString string, args ...interface{})
CreateLogFile(prefix string)
2019-11-13 11:19:04 -05:00
}
type baseLogData struct {
data log.Fields
}
2019-11-13 11:19:04 -05:00
type LoggerImpl struct {
*baseLogData
2019-11-20 13:33:46 -05:00
Type int
AllowOnConsole bool
LogFile *os.File
2019-11-20 13:33:46 -05:00
next Logger
2019-11-13 11:19:04 -05:00
}
func (l *LoggerImpl) WithFields(logData log.Fields) *LoggerImpl {
l.data = logData
return l
}
func (l *LoggerImpl) WithField(key string, value string) *LoggerImpl {
l.data[key] = value
return l
}
2019-11-13 11:19:04 -05:00
func (l *LoggerImpl) SetNext(logType Logger) {
l.next = logType
}
func (l LoggerImpl) Log(logType int, level log.Level, message string) {
2019-11-13 11:19:04 -05:00
if l.next != nil {
l.next.Log(logType, level, message)
2019-11-13 11:19:04 -05:00
}
}
func (l LoggerImpl) Logf(logType int, level log.Level, msgFmtString string, args ...interface{}) {
if l.next != nil {
l.next.Logf(logType, level, msgFmtString, args...)
}
}
func (l *LoggerImpl) resetFields() {
l.data = nil
l.data = log.Fields{}
}