|
|
|
@ -15,10 +15,12 @@ import ( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
loggers []*Logger |
|
|
|
|
loggers []*Logger |
|
|
|
|
// GitLogger logger for git
|
|
|
|
|
GitLogger *Logger |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// NewLogger create a logger
|
|
|
|
|
func NewLogger(bufLen int64, mode, config string) { |
|
|
|
|
logger := newLogger(bufLen) |
|
|
|
|
|
|
|
|
@ -37,6 +39,7 @@ func NewLogger(bufLen int64, mode, config string) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewGitLogger create a logger for git
|
|
|
|
|
// FIXME: use same log level as other loggers.
|
|
|
|
|
func NewGitLogger(logPath string) { |
|
|
|
|
os.MkdirAll(path.Dir(logPath), os.ModePerm) |
|
|
|
@ -44,42 +47,49 @@ func NewGitLogger(logPath string) { |
|
|
|
|
GitLogger.SetLogger("file", fmt.Sprintf(`{"level":0,"filename":"%s","rotate":false}`, logPath)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Trace records trace log
|
|
|
|
|
func Trace(format string, v ...interface{}) { |
|
|
|
|
for _, logger := range loggers { |
|
|
|
|
logger.Trace(format, v...) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Debug records debug log
|
|
|
|
|
func Debug(format string, v ...interface{}) { |
|
|
|
|
for _, logger := range loggers { |
|
|
|
|
logger.Debug(format, v...) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Info records info log
|
|
|
|
|
func Info(format string, v ...interface{}) { |
|
|
|
|
for _, logger := range loggers { |
|
|
|
|
logger.Info(format, v...) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Warn records warnning log
|
|
|
|
|
func Warn(format string, v ...interface{}) { |
|
|
|
|
for _, logger := range loggers { |
|
|
|
|
logger.Warn(format, v...) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Error records error log
|
|
|
|
|
func Error(skip int, format string, v ...interface{}) { |
|
|
|
|
for _, logger := range loggers { |
|
|
|
|
logger.Error(skip, format, v...) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Critical records critical log
|
|
|
|
|
func Critical(skip int, format string, v ...interface{}) { |
|
|
|
|
for _, logger := range loggers { |
|
|
|
|
logger.Critical(skip, format, v...) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Fatal records error log and exit process
|
|
|
|
|
func Fatal(skip int, format string, v ...interface{}) { |
|
|
|
|
Error(skip, format, v...) |
|
|
|
|
for _, l := range loggers { |
|
|
|
@ -88,6 +98,7 @@ func Fatal(skip int, format string, v ...interface{}) { |
|
|
|
|
os.Exit(1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Close closes all the loggers
|
|
|
|
|
func Close() { |
|
|
|
|
for _, l := range loggers { |
|
|
|
|
l.Close() |
|
|
|
@ -101,8 +112,10 @@ func Close() { |
|
|
|
|
// |___|___| /__| \___ >__| |__| (____ /\___ >___ >
|
|
|
|
|
// \/ \/ \/ \/ \/
|
|
|
|
|
|
|
|
|
|
type LogLevel int |
|
|
|
|
// LogLevel level type for log
|
|
|
|
|
//type LogLevel int
|
|
|
|
|
|
|
|
|
|
// log levels
|
|
|
|
|
const ( |
|
|
|
|
TRACE = iota |
|
|
|
|
DEBUG |
|
|
|
@ -274,36 +287,43 @@ func (l *Logger) Close() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Trace records trace log
|
|
|
|
|
func (l *Logger) Trace(format string, v ...interface{}) { |
|
|
|
|
msg := fmt.Sprintf("[T] "+format, v...) |
|
|
|
|
l.writerMsg(0, TRACE, msg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Debug records debug log
|
|
|
|
|
func (l *Logger) Debug(format string, v ...interface{}) { |
|
|
|
|
msg := fmt.Sprintf("[D] "+format, v...) |
|
|
|
|
l.writerMsg(0, DEBUG, msg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Info records information log
|
|
|
|
|
func (l *Logger) Info(format string, v ...interface{}) { |
|
|
|
|
msg := fmt.Sprintf("[I] "+format, v...) |
|
|
|
|
l.writerMsg(0, INFO, msg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Warn records warnning log
|
|
|
|
|
func (l *Logger) Warn(format string, v ...interface{}) { |
|
|
|
|
msg := fmt.Sprintf("[W] "+format, v...) |
|
|
|
|
l.writerMsg(0, WARN, msg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Error records error log
|
|
|
|
|
func (l *Logger) Error(skip int, format string, v ...interface{}) { |
|
|
|
|
msg := fmt.Sprintf("[E] "+format, v...) |
|
|
|
|
l.writerMsg(skip, ERROR, msg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Critical records critical log
|
|
|
|
|
func (l *Logger) Critical(skip int, format string, v ...interface{}) { |
|
|
|
|
msg := fmt.Sprintf("[C] "+format, v...) |
|
|
|
|
l.writerMsg(skip, CRITICAL, msg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Fatal records error log and exit the process
|
|
|
|
|
func (l *Logger) Fatal(skip int, format string, v ...interface{}) { |
|
|
|
|
msg := fmt.Sprintf("[F] "+format, v...) |
|
|
|
|
l.writerMsg(skip, FATAL, msg) |
|
|
|
|