github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/log/root.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:41</date>
    10  //</624342646839578624>
    11  
    12  package log
    13  
    14  import (
    15  	"os"
    16  )
    17  
    18  var (
    19  	root          = &logger{[]interface{}{}, new(swapHandler)}
    20  	StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat())
    21  	StderrHandler = StreamHandler(os.Stderr, LogfmtFormat())
    22  )
    23  
    24  func init() {
    25  	root.SetHandler(DiscardHandler())
    26  }
    27  
    28  //new返回具有给定上下文的新记录器。
    29  //new是根()的方便别名。new
    30  func New(ctx ...interface{}) Logger {
    31  	return root.New(ctx...)
    32  }
    33  
    34  //根返回根记录器
    35  func Root() Logger {
    36  	return root
    37  }
    38  
    39  //以下函数绕过导出的记录器方法(logger.debug,
    40  //等)保持所有日志记录器路径的调用深度相同。
    41  //运行时。调用方(2)总是在客户端代码中引用调用站点。
    42  
    43  //trace是根()的方便别名。
    44  func Trace(msg string, ctx ...interface{}) {
    45  	root.write(msg, LvlTrace, ctx, skipLevel)
    46  }
    47  
    48  //debug是根()的方便别名。debug
    49  func Debug(msg string, ctx ...interface{}) {
    50  	root.write(msg, LvlDebug, ctx, skipLevel)
    51  }
    52  
    53  //info是根()的方便别名。info
    54  func Info(msg string, ctx ...interface{}) {
    55  	root.write(msg, LvlInfo, ctx, skipLevel)
    56  }
    57  
    58  //warn是根()的方便别名。warn
    59  func Warn(msg string, ctx ...interface{}) {
    60  	root.write(msg, LvlWarn, ctx, skipLevel)
    61  }
    62  
    63  //错误是根()的方便别名。错误
    64  func Error(msg string, ctx ...interface{}) {
    65  	root.write(msg, LvlError, ctx, skipLevel)
    66  }
    67  
    68  //crit是root()的方便别名。
    69  func Crit(msg string, ctx ...interface{}) {
    70  	root.write(msg, LvlCrit, ctx, skipLevel)
    71  	os.Exit(1)
    72  }
    73  
    74  //输出是一个方便的写别名,允许修改
    75  //调用深度(要跳过的堆栈帧数)。
    76  //CallDepth影响日志消息的报告行号。
    77  //CallDepth为零将报告输出的直接调用方。
    78  //非零callDepth跳过的堆栈帧越多。
    79  func Output(msg string, lvl Lvl, calldepth int, ctx ...interface{}) {
    80  	root.write(msg, lvl, ctx, calldepth+skipLevel)
    81  }
    82