type Logger struct {
mu sync.Mutex
prefix string
flag int
out io.Writer
buf []byte
}
用于记录日志,sync.Mutex 锁mu, prefix 每条日志的前缀,flag 有Ldata Ltime Lmicroseconds Llongfile Lshortfile LUTC LstdfFlags(Ldate | Ltime), out 输出端, buf 日志缓存端
func New(out io.Writer, prefix string, flag int) *Logger
生成Logger对象
func (l *Logger)SetOutput(w io.Writer)
设置输出端
func itoa(buf *[]byte, i int, wid int)
将i转换为ASCII 宽度限制为wid
func (l *Logger)formatHeader(buf *[]byte, t time.Time, file string, line int)
格式化输出 Ldate+’ ‘+Ltime+’ ‘+Llongfile/Lshortfile+’:’+line
func (l *Logger) Output(calldepth int, s string) error
输出:格式化+’\n’+out.Write(l.buf), calldepth: file路径深度
func (l *Logger) Printf(format string, v ...interface{})
Printf 调用Logger::Output并且path=2
func (l *Logger) Print(v interface{})
Print无格式直接输出
func (l *Logger) Println(v ...interface{})
Println->fmt.Sprintln()->fmt.Println()->l.Output
func (l *Logger) Fatal(v ...interface{})
l.Fatal->fmt.Sprint->l.Output->os.Exit(1)
func (l *Logger) Fatalf(format string, v ...interface{})
l.Fatalf->fmt.Sprintf->l.Output->os.Exit(1)
func (l *Logger) Fatalln(v ...interface{})
l.Fatalln->fmt.Sprintln->l.Output->os.Exit(1)
func (l *Logger) Panic(v ...interface{})
l.Panic->fmt.Sprint->l.Output->panic(s)
func (l *Logger) Panicf(format string, v ...interface{})
l.Panicf->fmt.Sprintf->l.Output->panic(s)
func (l *Logger) Panicln(v ...interface{})
l.Panicln->fmt.Sprintln->l.Output(2, s)->panic(s)
func (l *Logger) Flags() int
获取flag
func (l *logger) SetFlags(flag int)
设置Flag
func (l *Logger) Prefix() string
获取prefix string
func (l *Logger) SetPrefix(prefix string)
设置prefix string
var std = New(os.Stderr, "", LstdFlags)
标准错误输出
func Flag()int
func SetFlag(flag int)
调用std.Flag std.SetFlag
func Prefix()string
func SetPrefix(prefix string)
调用std.Prefix std.SetPrefix
func Print(v ...interface{})
func Printf(format string, v ...interface{})
func Println(v ...interface{})
调用std.Print std.Printf…
func Fatal(v ...interface{})
func Fatalf(format string, v ...interface{})
func Fatalln(v ...interface{})
调用std.Fatal std.Fatalf…
func Panic(v ...interface{})
func Panicf(format string, v ...interface{})
func Panicln(v ...interface{})
调用std.Panic std.Panicf std.Panicln..
func Output(calldepth int, s string) error
调用std.Output
// Calldepth is the count of the number of
// frames to skip when computing the file name and line number
// if Llongfile or Lshortfile is set;