Documentation
¶
Index ¶
- Constants
- func ColorByMethod(method string) string
- func ColorByStatus(code int) string
- func CreateDirIfNotExists(path string) error
- func Debug(format any, a ...interface{})
- func Error(format any, a ...interface{})
- func Exists(path string) bool
- func Fatal(format any, a ...interface{})
- func FileWrite(path string) io.Writer
- func Info(format any, a ...interface{})
- func NewConsole() *consoleWriter
- func Panic(format any, a ...interface{})
- func ResetColor() string
- func Set(options ...Options)
- func SetLevelWriter(level string, w ...io.Writer)
- func Warn(format any, a ...interface{})
- type DefaultFormat
- type Formatter
- type Log
- func (logger *Log) Close()
- func (l *Log) Debug(format any, a ...interface{})
- func (l *Log) Error(format any, a ...interface{})
- func (l *Log) Fatal(format any, a ...interface{})
- func (l *Log) Info(format any, a ...interface{})
- func (l *Log) Panic(format any, a ...interface{})
- func (l *Log) SetFlag(flag int)
- func (l *Log) SetFormatter(level string)
- func (l *Log) SetLevel(level int32)
- func (l *Log) SetLevelWriter(level string, w ...io.Writer)
- func (l *Log) SetPrefix(flag int) *Log
- func (l *Log) SetWriter(w io.Writer)
- func (l *Log) Warn(format any, a ...interface{})
- func (l *Log) WithLevel(level string)
- type Logger
- type Option
- func (p *Option) CallPath(pc uintptr) (file string, line int)
- func (l *Option) File(buf *[]byte)
- func (p *Option) Flags() int
- func (l *Option) Prefix() string
- func (p *Option) PrintLevel(level int32) string
- func (p *Option) SetFlags(flag int)
- func (l *Option) SetPrefix(prefix string)
- func (l *Option) Time(buf *[]byte, t time.Time)
- type Options
Constants ¶
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 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 LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone Lmsgprefix // move the "prefix" from the beginning of the line to before the message LstdFlags = Ldate | Ltime // initial values for the standard logger )
These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. With the exception of the Lmsgprefix flag, there is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,
2009/01/23 01:23:23 message
while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,
2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
Variables ¶
This section is empty.
Functions ¶
func ColorByMethod ¶
ColorByMethod return color by http code
func ColorByStatus ¶
ColorByStatus return color by http code 2xx return Green 3xx return White 4xx return Yellow 5xx return Red
func CreateDirIfNotExists ¶
CreateDirIfNotExists 目录不存在时创建目录
func NewConsole ¶
func NewConsole() *consoleWriter
NewConsole creates ConsoleWriter returning as LoggerInterface.
func SetLevelWriter ¶
为指定等级的日志设置额外的输出 通常用于需要特别关注的紧急日志
Types ¶
type DefaultFormat ¶
type DefaultFormat 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 (*DefaultFormat) Format ¶
func (l *DefaultFormat) Format(lm *Option, level int32, s string, args ...interface{}) []byte
Format implements log.Formatter.
func (*DefaultFormat) Prefix ¶
func (l *DefaultFormat) Prefix() string
Prefix returns the output prefix for the logger.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Logger Logger
func Default ¶
func Default() *Log
Default returns the standard logger used by the package-level output functions.
func New ¶
New creates a new Logger. The out variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line, or after the log header if the Lmsgprefix flag is provided. The flag argument defines the logging properties.
func (*Log) SetLevelWriter ¶
为指定等级的日志设置额外的输出 通常用于需要特别关注的紧急日志
type Option ¶
type Option struct { CallDepth int Level int32 Flag int ShowFuncName bool // contains filtered or unexported fields }
func (*Option) Flags ¶
Flags returns the output flags for the logger. The flag bits are Ldate, Ltime, and so on.
func (*Option) PrintLevel ¶
func (*Option) SetFlags ¶
SetFlags sets the output flags for the logger. The flag bits are Ldate, Ltime, and so on.