github.com/wasm0/zkwasm-geth@v1.9.7/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, skipLevel) 35 } 36 37 // Debug is a convenient alias for Root().Debug 38 func Debug(msg string, ctx ...interface{}) { 39 root.write(msg, LvlDebug, ctx, skipLevel) 40 } 41 42 // Info is a convenient alias for Root().Info 43 func Info(msg string, ctx ...interface{}) { 44 root.write(msg, LvlInfo, ctx, skipLevel) 45 } 46 47 // Warn is a convenient alias for Root().Warn 48 func Warn(msg string, ctx ...interface{}) { 49 root.write(msg, LvlWarn, ctx, skipLevel) 50 } 51 52 // Error is a convenient alias for Root().Error 53 func Error(msg string, ctx ...interface{}) { 54 root.write(msg, LvlError, ctx, skipLevel) 55 } 56 57 // Crit is a convenient alias for Root().Crit 58 func Crit(msg string, ctx ...interface{}) { 59 root.write(msg, LvlCrit, ctx, skipLevel) 60 os.Exit(1) 61 } 62 63 // Output is a convenient alias for write, allowing for the modification of 64 // the calldepth (number of stack frames to skip). 65 // calldepth influences the reported line number of the log message. 66 // A calldepth of zero reports the immediate caller of Output. 67 // Non-zero calldepth skips as many stack frames. 68 func Output(msg string, lvl Lvl, calldepth int, ctx ...interface{}) { 69 root.write(msg, lvl, ctx, calldepth+skipLevel) 70 }