xlog

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 12 Imported by: 0

README

xlog

简介

xlog 是一个日志库,基于 rs/zerolog: Zero Allocation JSON Logger

  • 支持定义:
    • 屏幕输出和文件输出日志级别
    • 屏幕输出是否带颜色
    • 文件输出支持 gopkg.in/natefinch/lumberjack.v2
    • 由于with应该谨慎使用,所以不支持with模式
    • 支持动态更新日志配置(不上锁, 线程不安全),用意是可以先生成logger实例(全局变量),后初始化, 初始化后会更新已经生成的logger实例

TODO:

  • 支持context
  • 改用 https://github.com/jedib0t/go-pretty 输出 asci escape codes

Documentation

Overview

* @Description: * @Author: linzhengmao * @Email: [email protected] * @Date: 2025-09-26 14:33:33 * @LastEditTime: 2026-01-08 12:07:53 * @LastEditors: linzhengmao

* @Description: * @Author: linzhengmao * @Email: [email protected] * @Date: 2025-09-26 22:43:01 * @LastEditTime: 2026-01-08 14:29:04 * @LastEditors: linzhengmao

* @Description: * @Author: linzhengmao * @Email: [email protected] * @Date: 2025-09-26 14:33:38 * @LastEditTime: 2026-01-08 14:29:56 * @LastEditors: linzhengmao

* @Description: * @Author: linzhengmao * @Email: [email protected] * @Date: 2025-09-26 14:40:47 * @LastEditTime: 2026-01-08 12:28:15 * @LastEditors: linzhengmao

Index

Constants

View Source
const (
	BASE_SKIP = 3
)

Variables

This section is empty.

Functions

func Close

func Close()

func Debug

func Debug(msg string, args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func DebugfCallerSkip

func DebugfCallerSkip(skip int, format string, args ...interface{})

func Error

func Error(msg string, args ...interface{})

func ErrorE

func ErrorE(err error)

func ErrorECallerSkip

func ErrorECallerSkip(skip int, err error)

func Errorf

func Errorf(format string, args ...interface{})

func ErrorfCallerSkip

func ErrorfCallerSkip(skip int, format string, args ...interface{})

func Fatal

func Fatal(msg string, args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func FatalfCallerSkip

func FatalfCallerSkip(skip int, format string, args ...interface{})

func GetColorMessage

func GetColorMessage(color ColorType, format string, args ...interface{}) string

func HexDump

func HexDump(data []byte, length int) string

HexDump 简洁版本的十六进制转储函数 输入: data - 字节数组, length - 要显示的长度 输出: 格式化的十六进制转储字符串

func HexDumpCustom

func HexDumpCustom(data []byte, length int, lineSize int) string

HexDumpCustom 支持自定义行大小的版本 输入: data - 字节数组, length - 要显示的长度, lineSize - 每行字节数(自动调整为4的倍数) 输出: 格式化的十六进制转储字符串

func Info

func Info(msg string, args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func InfofCallerSkip

func InfofCallerSkip(skip int, format string, args ...interface{})

func PrintInstances

func PrintInstances()

func Raw

func Raw(color ColorType, message string, args ...interface{})

func RawWithInfo

func RawWithInfo(color ColorType, title string, format string, args ...interface{})

func Rawln

func Rawln(color ColorType, message string, args ...interface{})

func Setup

func Setup(config *Config) error

func Trace

func Trace(msg string, args ...interface{})

func Tracef

func Tracef(format string, args ...interface{})

func TracefCallerSkip

func TracefCallerSkip(skip int, format string, args ...interface{})

func UpdateLoggerInstance

func UpdateLoggerInstance()

func Warn

func Warn(msg string, args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func WarnfCallerSkip

func WarnfCallerSkip(skip int, format string, args ...interface{})

Types

type Cache

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

func NewCache

func NewCache(maxSize int) *Cache

type ColorType

type ColorType int
const (
	ColorNone ColorType = iota
	ColorBlue
	ColorRed
	ColorYellow
	ColorGreen
	ColorBlueBg
	ColorRedBg
	ColorYellowBg
	ColorGreenBg
	ColorWarn
)

type Config

type Config struct {
	ConsoleEnable bool
	FileEnable    bool
	Sugar         bool // 屏幕输出颜色,输出caller
	// AddSource     bool
	Console ConsoleConfig
	File    FileConfig
}

func GetCurConfig

func GetCurConfig() *Config

func GetDefaultConfig

func GetDefaultConfig() *Config

type ConsoleConfig

type ConsoleConfig struct {
	Level string
}

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field 日志字段

type FileConfig

type FileConfig struct {
	Level      string
	Path       string
	MaxSize    int // MB
	MaxAge     int // days
	MaxBackups int
	Compress   bool // 是否压缩旧日志文件
}

Config 日志配置

type Xlogger

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

模块专用logger

func GetLogger

func GetLogger() *Xlogger

func GetLoggerModule

func GetLoggerModule(name string) *Xlogger

func GetLoggerModuleWithCallerSkip

func GetLoggerModuleWithCallerSkip(name string, skip int) *Xlogger

func (*Xlogger) Debug

func (l *Xlogger) Debug(msg string, args ...interface{})

func (*Xlogger) Debugf

func (l *Xlogger) Debugf(format string, args ...interface{})

func (*Xlogger) DebugfCallerSkip

func (l *Xlogger) DebugfCallerSkip(skip int, format string, args ...interface{})

func (*Xlogger) Error

func (l *Xlogger) Error(msg string, args ...interface{})

func (*Xlogger) ErrorE

func (l *Xlogger) ErrorE(err error)

func (*Xlogger) ErrorECallSkip

func (l *Xlogger) ErrorECallSkip(skip int, err error)

func (*Xlogger) Errorf

func (l *Xlogger) Errorf(format string, args ...interface{})

func (*Xlogger) ErrorfCallerSkip

func (l *Xlogger) ErrorfCallerSkip(skip int, format string, args ...interface{})

func (*Xlogger) Fatal

func (l *Xlogger) Fatal(msg string, args ...interface{})

func (*Xlogger) Fatalf

func (l *Xlogger) Fatalf(format string, args ...interface{})

func (*Xlogger) FatalfCallerSkip

func (l *Xlogger) FatalfCallerSkip(skip int, format string, args ...interface{})

func (*Xlogger) GetLoggerBase

func (l *Xlogger) GetLoggerBase() zerolog.Logger

func (*Xlogger) Info

func (l *Xlogger) Info(msg string, args ...interface{})

func (*Xlogger) Infof

func (l *Xlogger) Infof(format string, args ...interface{})

func (*Xlogger) InfofCallerSkip

func (l *Xlogger) InfofCallerSkip(skip int, format string, args ...interface{})

func (*Xlogger) Sync

func (l *Xlogger) Sync() error

func (*Xlogger) Trace

func (l *Xlogger) Trace(msg string, args ...interface{})

func (*Xlogger) Tracef

func (l *Xlogger) Tracef(format string, args ...interface{})

func (*Xlogger) TracefCallerSkip

func (l *Xlogger) TracefCallerSkip(skip int, format string, args ...interface{})

func (*Xlogger) Warn

func (l *Xlogger) Warn(msg string, args ...interface{})

func (*Xlogger) Warnf

func (l *Xlogger) Warnf(format string, args ...interface{})

func (*Xlogger) WarnfCallerSkip

func (l *Xlogger) WarnfCallerSkip(skip int, format string, args ...interface{})

func (*Xlogger) WithCallerSkip

func (l *Xlogger) WithCallerSkip(module string, skip int) *Xlogger

Directories

Path Synopsis
* @Description: * @Author: moo * @Email: [email protected] * @Date: 2021-01-04 23:22:43 * @LastEditTime: 2026-01-08 12:08:09 * @LastEditors: linzhengmao
* @Description: * @Author: moo * @Email: [email protected] * @Date: 2021-01-04 23:22:43 * @LastEditTime: 2026-01-08 12:08:09 * @LastEditors: linzhengmao
* @Description: * @Author: linzhengmao * @Email: [email protected] * @Date: 2025-09-26 18:27:11 * @LastEditTime: 2026-01-08 14:42:23 * @LastEditors: linzhengmao
* @Description: * @Author: linzhengmao * @Email: [email protected] * @Date: 2025-09-26 18:27:11 * @LastEditTime: 2026-01-08 14:42:23 * @LastEditors: linzhengmao

Jump to

Keyboard shortcuts

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