log

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 10 Imported by: 0

README

log

go log

Documentation

Index

Constants

View Source
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

func ColorByMethod(method string) string

ColorByMethod return color by http code

func ColorByStatus

func ColorByStatus(code int) string

ColorByStatus return color by http code 2xx return Green 3xx return White 4xx return Yellow 5xx return Red

func CreateDirIfNotExists

func CreateDirIfNotExists(path string) error

CreateDirIfNotExists 目录不存在时创建目录

func Debug

func Debug(format any, a ...interface{})

Debug Debug

func Error

func Error(format any, a ...interface{})

Error Error

func Exists

func Exists(path string) bool

Exists 判断所给路径文件/文件夹是否存在

func Fatal

func Fatal(format any, a ...interface{})

Fatal Fatal

func FileWrite

func FileWrite(path string) io.Writer

func Info

func Info(format any, a ...interface{})

Info Info

func NewConsole

func NewConsole() *consoleWriter

NewConsole creates ConsoleWriter returning as LoggerInterface.

func Panic

func Panic(format any, a ...interface{})

Error Error

func ResetColor

func ResetColor() string

ResetColor return reset color

func Set

func Set(options ...Options)

Set log

func SetLevelWriter

func SetLevelWriter(level string, w ...io.Writer)

为指定等级的日志设置额外的输出 通常用于需要特别关注的紧急日志

func Warn

func Warn(format any, a ...interface{})

Warn Warn

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 Formatter

type Formatter interface {
	// Name() string      // 格式器名称
	// Option(lm *Option) // 用于调整适合此格式器的默认配置
	Format(lm *Option, level int32, msg string, args ...interface{}) []byte
}

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

func New(out io.Writer, prefix string, flags ...int) *Log

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) Close

func (logger *Log) Close()

Close It's dangerous to call the method on logging

func (*Log) Debug

func (l *Log) Debug(format any, a ...interface{})

Debug Debug

func (*Log) Error

func (l *Log) Error(format any, a ...interface{})

Error Error

func (*Log) Fatal

func (l *Log) Fatal(format any, a ...interface{})

Fatal Fatal

func (*Log) Info

func (l *Log) Info(format any, a ...interface{})

Info Info

func (*Log) Panic

func (l *Log) Panic(format any, a ...interface{})

Panic Panic

func (*Log) SetFlag

func (l *Log) SetFlag(flag int)

设置日志显示格式 需要注意,对于一些自定义的formatter,它并不是绝对生效的

func (*Log) SetFormatter

func (l *Log) SetFormatter(level string)

设置日志格式器

func (*Log) SetLevel

func (l *Log) SetLevel(level int32)

SetLevel SetLevel

func (*Log) SetLevelWriter

func (l *Log) SetLevelWriter(level string, w ...io.Writer)

为指定等级的日志设置额外的输出 通常用于需要特别关注的紧急日志

func (*Log) SetPrefix

func (l *Log) SetPrefix(flag int) *Log

通常我们需要把日志传递给第三方模块使用,并想要标记是第三方模块 那么可以使用此函数获取一个带有指定标记的日志实例

func (*Log) SetWriter

func (l *Log) SetWriter(w io.Writer)

设置日志输出

func (*Log) Warn

func (l *Log) Warn(format any, a ...interface{})

Warn Warn

func (*Log) WithLevel

func (l *Log) WithLevel(level string)

WithPath 设置日志输出路径

type Logger

type Logger interface {
	Debug(msg any, a ...interface{})
	Info(msg any, a ...interface{})
	Warn(msg any, a ...interface{})
	Error(msg any, a ...interface{})
	Panic(msg any, a ...interface{})
	Fatal(msg any, a ...interface{})
}

type Option

type Option struct {
	CallDepth    int
	Level        int32
	Flag         int
	ShowFuncName bool
	// contains filtered or unexported fields
}

func (*Option) CallPath

func (p *Option) CallPath(pc uintptr) (file string, line int)

func (*Option) File

func (l *Option) File(buf *[]byte)

func (*Option) Flags

func (p *Option) Flags() int

Flags returns the output flags for the logger. The flag bits are Ldate, Ltime, and so on.

func (*Option) Prefix

func (l *Option) Prefix() string

Prefix returns the output prefix for the logger.

func (*Option) PrintLevel

func (p *Option) PrintLevel(level int32) string

func (*Option) SetFlags

func (p *Option) SetFlags(flag int)

SetFlags sets the output flags for the logger. The flag bits are Ldate, Ltime, and so on.

func (*Option) SetPrefix

func (l *Option) SetPrefix(prefix string)

SetPrefix sets the output prefix for the logger.

func (*Option) Time

func (l *Option) Time(buf *[]byte, t time.Time)

type Options

type Options func(g *Log)

func WithLevel

func WithLevel(level string) Options

WithPath 设置日志输出路径

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL