github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/log/root.go (about) 1 package log 2 3 import ( 4 "os" 5 ) 6 7 var ( 8 root = &logger{[]interface{}{}, new(swapHandler)} 9 StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat()) 10 StderrHandler = StreamHandler(os.Stderr, LogfmtFormat()) 11 ) 12 13 func init() { 14 root.SetHandler(DiscardHandler()) 15 } 16 17 // New returns a new logger with the given context. 18 // New is a convenient alias for Root().New 19 func New(ctx ...interface{}) Logger { 20 return root.New(ctx...) 21 } 22 23 // Root returns the root logger 24 func Root() Logger { 25 return root 26 } 27 28 // The following functions bypass the exported logger methods (logger.Debug, 29 // etc.) to keep the call depth the same for all paths to logger.write so 30 // runtime.Caller(2) always refers to the call site in client code. 31 32 // Trace is a convenient alias for Root().Trace 33 func Trace(msg string, ctx ...interface{}) { 34 root.write(msg, LvlTrace, ctx) 35 } 36 37 // Debug is a convenient alias for Root().Debug 38 func Debug(msg string, ctx ...interface{}) { 39 root.write(msg, LvlDebug, ctx) 40 } 41 42 // Info is a convenient alias for Root().Info 43 func Info(msg string, ctx ...interface{}) { 44 root.write(msg, LvlInfo, ctx) 45 } 46 47 // Warn is a convenient alias for Root().Warn 48 func Warn(msg string, ctx ...interface{}) { 49 root.write(msg, LvlWarn, ctx) 50 } 51 52 // Error is a convenient alias for Root().Error 53 func Error(msg string, ctx ...interface{}) { 54 root.write(msg, LvlError, ctx) 55 } 56 57 // Crit is a convenient alias for Root().Crit 58 func Crit(msg string, ctx ...interface{}) { 59 root.write(msg, LvlCrit, ctx) 60 os.Exit(1) 61 }