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