logger

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 15 Imported by: 32

README

logger

convenient log package

1. 使用说明

    // 配置logger,如果不配置时默认为控制台输出,等级为DEBUG
    logger.SetLogger(`{"Console": {"level": "DEBG"}`)
    // 配置说明见下文

    // 设置完成后,即可在控制台和日志文件app.log中看到如下输出
    logger.Debug("this is Debug")
    logger.Trace("this is Trace")
    logger.Alert("this is Alert")
    logger.Error("this is Error")
    logger.Panic("this is Panic")
    logger.Fatal("this is Fatal")

2. 日志等级

当前日志输出等级共6种,对应的等级由底到高,当配置为某个输出等级时,只有大于等于该等级的日志才会输出

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Console = &console{colorful: true}

Functions

func Alert

func Alert(f any, v ...any)

func Debug

func Debug(f any, v ...any)

func DelOutput added in v0.0.4

func DelOutput(name string)

func Error

func Error(f any, v ...any)

func Fatal

func Fatal(f any, v ...any)

func Panic added in v0.0.2

func Panic(f any, v ...any)

func SetCallDepth added in v0.0.2

func SetCallDepth(depth int)

func SetLevel added in v0.0.2

func SetLevel(level Level)

SetLevel 设置日志输出等级

func SetOutput added in v0.0.2

func SetOutput(name string, output Output) error

func SetPathTrim added in v0.0.2

func SetPathTrim(trimPath ...string)

SetPathTrim 设置日志起始路径

func Sprintf added in v0.0.2

func Sprintf(format any, args ...any) (text string)

func Trace

func Trace(f any, v ...any)

Types

type Conn added in v0.0.2

type Conn struct {
	sync.Mutex
	Network   string `json:"network"`
	Address   string `json:"address"`
	Reconnect bool   `json:"reconnect"`
	Format    func(*Message) string
	// contains filtered or unexported fields
}

func NewConn added in v0.0.2

func NewConn(network, address string) *Conn

func (*Conn) Close added in v0.0.2

func (c *Conn) Close()

func (*Conn) Init added in v0.0.2

func (c *Conn) Init() error

func (*Conn) Name added in v0.0.2

func (c *Conn) Name() string

func (*Conn) Write added in v0.0.2

func (c *Conn) Write(msg *Message) (err error)

type File added in v0.0.2

type File struct {
	Sprintf func(*Message) *strings.Builder //格式化message
	// contains filtered or unexported fields
}

func NewFile added in v0.0.2

func NewFile(path string) *File

func (*File) GetFileName added in v0.0.3

func (this *File) GetFileName() (name string, expire int64)

func (*File) MayBackup added in v0.1.0

func (this *File) MayBackup() error

func (*File) SetFileName added in v0.0.3

func (this *File) SetFileName(f file.NameFormatter)

SetFileName 设置日志文件名, 前缀(string) 或者 fileNameFormatter

func (*File) SetFileSize added in v0.1.0

func (this *File) SetFileSize(n int64)

SetFileSize 设置文件大小(M),默认无限制

func (*File) Write added in v0.0.2

func (this *File) Write(msg *Message) (err error)

type Level added in v0.0.2

type Level int8
const (
	LevelDebug Level = 0 // 用户级调试
	LevelTrace Level = 1 // 用户级基本输出
	LevelAlert Level = 2 //一般性警告
	LevelError Level = 7 // 用户级错误
	LevelPanic Level = 8 //Panic
	LevelFATAL Level = 9 //PANIC
)

日志等级,从0-7,日优先级由高到低

func (Level) Brush added in v0.0.2

func (l Level) Brush(text string) string

func (Level) String added in v0.0.2

func (l Level) String() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func New

func New(depth ...int) *Logger

func (*Logger) Alert

func (this *Logger) Alert(format interface{}, args ...interface{})

func (*Logger) Debug

func (this *Logger) Debug(format interface{}, v ...interface{})

Debug Log DEBUG level message.

func (*Logger) DelOutput added in v0.0.2

func (this *Logger) DelOutput(name string)

func (*Logger) Error

func (this *Logger) Error(format interface{}, v ...interface{})

Error Log ERROR level message.

func (*Logger) Fatal

func (this *Logger) Fatal(format any, args ...any)

func (*Logger) Panic added in v0.0.2

func (this *Logger) Panic(format any, args ...any)

func (*Logger) SetCallDepth

func (this *Logger) SetCallDepth(depth int)

func (*Logger) SetLevel added in v0.0.2

func (this *Logger) SetLevel(level Level)

SetLevel 设置日志输出等级

func (*Logger) SetOutput added in v0.0.2

func (this *Logger) SetOutput(name string, output Output) error

func (*Logger) SetPathTrim added in v0.0.2

func (this *Logger) SetPathTrim(trimPath ...string)

SetPathTrim 设置日志起始路径

func (*Logger) Sprint added in v0.0.4

func (this *Logger) Sprint(level Level, format any, args ...any)

func (*Logger) Trace

func (this *Logger) Trace(format interface{}, v ...interface{})

Trace Log TRAC level message.

func (*Logger) TrimPath added in v0.0.3

func (this *Logger) TrimPath(s string) (r string)

func (*Logger) Write added in v0.0.2

func (this *Logger) Write(msg *Message)

type Message

type Message struct {
	Path    string
	Time    time.Time
	Level   Level
	Stack   string
	Content string
}

func (*Message) Sprintf added in v0.1.0

func (this *Message) Sprintf() *strings.Builder

type Output added in v0.0.2

type Output interface {
	Write(message *Message) (err error)
}

Output Output输出时是否对字体染色

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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