github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/log/root.go (about)

     1  package log
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  )
     7  
     8  var (
     9  	root          = &logger{[]interface{}{}, new(swapHandler)}
    10  	StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat())
    11  	StderrHandler = StreamHandler(os.Stderr, LogfmtFormat())
    12  )
    13  
    14  func init() {
    15  	root.SetHandler(DiscardHandler())
    16  }
    17  
    18  func New(ctx ...interface{}) Logger {
    19  	return root.New(ctx...)
    20  }
    21  
    22  func Root() Logger {
    23  	return root
    24  }
    25  
    26  func Trace(msg string, ctx ...interface{}) {
    27  	root.write(msg, LvlTrace, ctx, skipLevel)
    28  }
    29  
    30  func Debug(msg string, ctx ...interface{}) {
    31  	root.write(msg, LvlDebug, ctx, skipLevel)
    32  }
    33  
    34  func Info(msg string, ctx ...interface{}) {
    35  	root.write(msg, LvlInfo, ctx, skipLevel)
    36  }
    37  
    38  func Warn(msg string, ctx ...interface{}) {
    39  	root.write(msg, LvlWarn, ctx, skipLevel)
    40  }
    41  
    42  func Error(msg string, ctx ...interface{}) {
    43  	root.write(msg, LvlError, ctx, skipLevel)
    44  }
    45  
    46  func Crit(msg string, ctx ...interface{}) {
    47  	root.write(msg, LvlCrit, ctx, skipLevel)
    48  	os.Exit(1)
    49  }
    50  
    51  func Output(msg string, lvl Lvl, calldepth int, ctx ...interface{}) {
    52  	root.write(msg, lvl, ctx, calldepth+skipLevel)
    53  }
    54  
    55  func Debugf(format string, args ...interface{}) {
    56  	root.write(fmt.Sprintf(format, args...), LvlDebug, nil, skipLevel)
    57  }
    58  
    59  func Infof(format string, args ...interface{}) {
    60  	root.write(fmt.Sprintf(format, args...), LvlInfo, nil, skipLevel)
    61  }
    62  
    63  func Warnf(format string, args ...interface{}) {
    64  	root.write(fmt.Sprintf(format, args...), LvlWarn, nil, skipLevel)
    65  }
    66  
    67  func Errorf(format string, args ...interface{}) {
    68  	root.write(fmt.Sprintf(format, args...), LvlError, nil, skipLevel)
    69  }