Documentation ¶
Overview ¶
Package log implements a simple logging package. It defines a type, Logger, with methods for formatting output. It also has a predefined 'standard' Logger accessible through helper functions Print[f|ln], Fatal[f|ln], and Panic[f|ln], which are easier to use than creating a Logger manually. That logger writes to standard error and prints the date and time of each logged message. The Fatal functions call os.Exit(1) after writing the log message. The Panic functions call panic after writing the log message.
Index ¶
- Constants
- Variables
- func ClearAll()
- func EnableColorLogger(loggerName string, enable bool) error
- func SetColorDefine(loggerName string, jsonFormat string) error
- func SetColorFile(loggerName string, colorFileName string) error
- func SetLevelByString(loggerName string, level string) error
- func SetOutputLogger(loggerName string, filename string) error
- func SetPanicLevelByString(loggerName string, level string) error
- func VisitLogger(name string, callback func(*Logger) bool) error
- type Color
- type ColorFile
- type ColorMatch
- type Level
- type Logger
- func (self *Logger) DebugColorf(colorName string, format string, v ...interface{})
- func (self *Logger) DebugColorln(colorName string, v ...interface{})
- func (self *Logger) Debugf(format string, v ...interface{})
- func (self *Logger) Debugln(v ...interface{})
- func (self *Logger) Errorf(format string, v ...interface{})
- func (self *Logger) Errorln(v ...interface{})
- func (self *Logger) Fatalf(format string, v ...interface{})
- func (self *Logger) Fatalln(v ...interface{})
- func (self *Logger) Flag() int
- func (self *Logger) Infof(format string, v ...interface{})
- func (self *Logger) Infoln(v ...interface{})
- func (self *Logger) IsDebugEnabled() bool
- func (self *Logger) Level() Level
- func (self *Logger) Log(c Color, level Level, format string, v ...interface{})
- func (self *Logger) Output(calldepth int, prefix string, text string, c Color, out io.Writer) error
- func (self *Logger) SetColorFile(file *ColorFile)
- func (self *Logger) SetFlag(v int)
- func (self *Logger) SetLevel(lv Level)
- func (self *Logger) SetLevelByString(level string)
- func (self *Logger) SetPanicLevelByString(level string)
- func (self *Logger) Warnf(format string, v ...interface{})
- func (self *Logger) Warnln(v ...interface{})
Constants ¶
const ( // Bits or'ed together to control what's printed. There is no control over the // order they appear (the order listed here) or the format they present (as // described in the comments). A colon appears after these items: // 2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message Ldate = 1 << iota // the date: 2009/01/23 Ltime // the time: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LstdFlags = Ldate | Ltime // initial values for the standard logger )
These flags define which text to prefix to each log entry generated by the Logger.
Variables ¶
var ErrLoggerNotFound = errors.New("logger not found")
Functions ¶
func EnableColorLogger ¶
func SetColorDefine ¶
func SetColorFile ¶
func SetLevelByString ¶
通过字符串设置某一类日志的级别
func SetOutputLogger ¶
func SetPanicLevelByString ¶
通过字符串设置某一类日志的崩溃级别
Types ¶
type ColorFile ¶
type ColorFile struct {
Rule []*ColorMatch
}
func NewColorFile ¶
func NewColorFile() *ColorFile
func (*ColorFile) ColorFromText ¶
type ColorMatch ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.
func (*Logger) DebugColorf ¶
func (*Logger) DebugColorln ¶
func (*Logger) IsDebugEnabled ¶
func (*Logger) Output ¶
Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.
func (*Logger) SetColorFile ¶
注意, 加色只能在Gogland的main方式启用, Test方式无法加色