export log levels and reverse log level order
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
7ce0305db4
commit
a606813fdf
@ -12,30 +12,30 @@ import (
|
|||||||
type Level int
|
type Level int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
trace Level = iota
|
LevelFatal Level = iota
|
||||||
debug
|
LevelInfo
|
||||||
info
|
LevelDebug
|
||||||
fatal
|
LevelTrace
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// the local logger
|
// the local logger
|
||||||
logger log.Logger = golog.New()
|
logger log.Logger = golog.New()
|
||||||
|
|
||||||
// default log level is debug
|
// default log level is info
|
||||||
level = info
|
level = LevelInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
switch os.Getenv("MICRO_LOG_LEVEL") {
|
switch os.Getenv("MICRO_LOG_LEVEL") {
|
||||||
case "debug":
|
case "debug":
|
||||||
level = debug
|
level = LevelDebug
|
||||||
case "info":
|
case "info":
|
||||||
level = info
|
level = LevelInfo
|
||||||
case "trace":
|
case "trace":
|
||||||
level = trace
|
level = LevelTrace
|
||||||
case "fatal":
|
case "fatal":
|
||||||
level = fatal
|
level = LevelFatal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ func Logf(format string, v ...interface{}) {
|
|||||||
|
|
||||||
// WithLevel logs with the level specified
|
// WithLevel logs with the level specified
|
||||||
func WithLevel(l Level, v ...interface{}) {
|
func WithLevel(l Level, v ...interface{}) {
|
||||||
if l < level {
|
if l > level {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Log(v...)
|
Log(v...)
|
||||||
@ -59,7 +59,7 @@ func WithLevel(l Level, v ...interface{}) {
|
|||||||
|
|
||||||
// WithLevel logs with the level specified
|
// WithLevel logs with the level specified
|
||||||
func WithLevelf(l Level, format string, v ...interface{}) {
|
func WithLevelf(l Level, format string, v ...interface{}) {
|
||||||
if l < level {
|
if l > level {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Logf(format, v...)
|
Logf(format, v...)
|
||||||
@ -67,43 +67,43 @@ func WithLevelf(l Level, format string, v ...interface{}) {
|
|||||||
|
|
||||||
// Trace provides trace level logging
|
// Trace provides trace level logging
|
||||||
func Trace(v ...interface{}) {
|
func Trace(v ...interface{}) {
|
||||||
WithLevel(trace, v...)
|
WithLevel(LevelTrace, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tracef provides trace level logging
|
// Tracef provides trace level logging
|
||||||
func Tracef(format string, v ...interface{}) {
|
func Tracef(format string, v ...interface{}) {
|
||||||
WithLevelf(trace, format, v...)
|
WithLevelf(LevelTrace, format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug provides debug level logging
|
// Debug provides debug level logging
|
||||||
func Debug(v ...interface{}) {
|
func Debug(v ...interface{}) {
|
||||||
WithLevel(debug, v...)
|
WithLevel(LevelDebug, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugf provides debug level logging
|
// Debugf provides debug level logging
|
||||||
func Debugf(format string, v ...interface{}) {
|
func Debugf(format string, v ...interface{}) {
|
||||||
WithLevelf(debug, format, v...)
|
WithLevelf(LevelDebug, format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info provides info level logging
|
// Info provides info level logging
|
||||||
func Info(v ...interface{}) {
|
func Info(v ...interface{}) {
|
||||||
WithLevel(info, v...)
|
WithLevel(LevelInfo, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infof provides info level logging
|
// Infof provides info level logging
|
||||||
func Infof(format string, v ...interface{}) {
|
func Infof(format string, v ...interface{}) {
|
||||||
WithLevelf(info, format, v...)
|
WithLevelf(LevelInfo, format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatal logs with Log and then exits with os.Exit(1)
|
// Fatal logs with Log and then exits with os.Exit(1)
|
||||||
func Fatal(v ...interface{}) {
|
func Fatal(v ...interface{}) {
|
||||||
WithLevel(fatal, v...)
|
WithLevel(LevelFatal, v...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf logs with Logf and then exits with os.Exit(1)
|
// Fatalf logs with Logf and then exits with os.Exit(1)
|
||||||
func Fatalf(format string, v ...interface{}) {
|
func Fatalf(format string, v ...interface{}) {
|
||||||
WithLevelf(fatal, format, v...)
|
WithLevelf(LevelFatal, format, v...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user