Documentation ¶
Index ¶
- Constants
- Variables
- type Log
- func (l *Log) AddFlag(flag int) *Log
- func (l *Log) Debug(v ...any)
- func (l *Log) Debugf(format string, v ...any)
- func (l *Log) Error(v ...any)
- func (l *Log) Errorf(format string, v ...any)
- func (parent *Log) Extend(options ...LogOption) *Log
- func (l *Log) Fatal(v ...any)
- func (l *Log) Fatalf(format string, v ...any)
- func (l *Log) Flag() int
- func (l *Log) Info(v ...any)
- func (l *Log) Infof(format string, v ...any)
- func (l *Log) Level() logLevel
- func (l *Log) Name() string
- func (l *Log) Order() []logOrder
- func (l *Log) Out(calldepth int, level logLevel, msg string) error
- func (l *Log) Output() io.Writer
- func (l *Log) Panic(v ...any)
- func (l *Log) Panicf(format string, v ...any)
- func (l *Log) Prefix() string
- func (l *Log) SetFlag(flag int) *Log
- func (l *Log) SetLevel(level logLevel) *Log
- func (l *Log) SetName(name string) *Log
- func (l *Log) SetOrder(orders ...logOrder) *Log
- func (l *Log) SetOutput(w1 io.Writer, w ...io.Writer) *Log
- func (l *Log) SetPrefix(prefix string) *Log
- func (l *Log) SubFlag(flag int) *Log
- func (l *Log) Trace(v ...any)
- func (l *Log) Tracef(format string, v ...any)
- func (l *Log) Warn(v ...any)
- func (l *Log) Warnf(format string, v ...any)
- type LogOption
- type Logger
Examples ¶
Constants ¶
View Source
const ( Discard logLevel = iota TraceLevel // 在线调试: 默认情况下,既不打印到终端也不输出到文件。此时,对程序运行效率几乎不产生影响。常用语 for 循环中调试 DebugLevel // 终端查看、在线调试: 默认情况下会打印到终端输出,但是不会归档到日志文件。因此,一般用于开发者在程序当前启动窗口上,查看日志流水信息。 InfoLevel // 报告程序进度和状态信息: 一般这种信息都是一过性的,不会大量反复输出。例如:连接商用库成功后,可以打印一条连库成功的信息,便于跟踪程序进展信息。 WarnLevel // 警告信息: 程序处理中遇到非法数据或者某种可能的错误。该错误是一过性的、可恢复的,不会影响程序继续运行,程序仍处在正常状态。 ErrorLevel // 状态错误: 该错误发生后程序仍然可以运行,但是极有可能运行在某种非正常的状态下,导致无法完成全部既定的功能。 PanicLevel // 致命的错误: 表明程序遇到了致命的错误,可以不马上终止运行,依赖 recover()。 FatalLevel // 致命的错误: 表明程序遇到了致命的错误,必须马上终止运行。 )
Fatal > Panic > Error > Warn > Info > Debug > Trace > Discard
View Source
const ( Fatal_ = "\x1b[0;30;45m " Panic_ = "\x1b[1;37;45m " Error_ = "\x1b[1;37;41m " Warn_ = "\x1b[0;30;43m " Info_ = "\x1b[0;30;46m " Debug_ = "\x1b[0;37;44m " Trace_ = "\x1b[0;30;42m " )
View Source
const ( OrderDate logOrder = "Date" OrderTime logOrder = "Time" OrderLevel logOrder = "Level" OrderPrefix logOrder = "Prefix" OrderPath logOrder = "Path" OrderMsg logOrder = "Message" )
View Source
const ( Ldate = 1 << iota Ltime Lmicroseconds LUTC Llongfile Lshortfile Lmsgprefix Lmsgcolor Llevel LlevelLabelColor LstdFlags = Ldate | Ltime | Lshortfile | Llevel )
Flag set include setting of date, time, path, prefix, level, msg
Variables ¶
View Source
var ( // Getter & Setter Output = std.Output Level = std.Level Name = std.Name Prefix = std.Prefix Order = std.Order Flag = std.Flag SetOutput = std.SetOutput SetLevel = std.SetLevel SetName = std.SetName SetPrefix = std.SetPrefix SetOrder = std.SetOrder SetFlag = std.SetFlag AddFlag = std.AddFlag SubFlag = std.SubFlag // Method Set Fatal = std.Fatal Panic = std.Panic Error = std.Error Warn = std.Warn Info = std.Info Debug = std.Debug Trace = std.Trace Fatalf = std.Fatalf Panicf = std.Panicf Errorf = std.Errorf Warnf = std.Warnf Infof = std.Infof Debugf = std.Debugf Tracef = std.Tracef )
Functions ¶
This section is empty.
Types ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
func Default ¶
func Default() *Log
Example ¶
var b1 bytes.Buffer SetOutput(&b1).SetFlag(Lshortfile) Info(`This is the default logger. It is often used for global logging.`) SetLevel(DebugLevel) Debug(`You can change the level of default logger by SetLevel().`) fmt.Println(b1.String())
Output: example_test.go:84 This is the default logger. It is often used for global logging. example_test.go:86 You can change the level of default logger by SetLevel().
Click to show internal directories.
Click to hide internal directories.