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
balandi1 bedfa52d7a Added functions to logging library
Added Logf() and WithFields() functions.
Logf() for logging formatted messages.
WithFields() for handling optional log fields.
2019-12-04 13:16:48 -05:00

54 lines
1.1 KiB
Go

package elektronLogging
import (
log "github.com/sirupsen/logrus"
"os"
)
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)
}
type baseLogData struct {
data log.Fields
}
type LoggerImpl struct {
*baseLogData
Type int
AllowOnConsole bool
LogFile *os.File
next Logger
}
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
}
func (l *LoggerImpl) SetNext(logType Logger) {
l.next = logType
}
func (l LoggerImpl) Log(logType int, level log.Level, message string) {
if l.next != nil {
l.next.Log(logType, level, message)
}
}
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{}
}