logger

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 4 Imported by: 2

README

日志组件

功能列表

  1. 支持混合输出流,比如控制台,日志文件
  2. 支持日志等级 debug,info,warn,error
  3. 支持结构化输出,比如JSON形式
  4. 支持日志切割,按照日期,时间间隔,文件大小切割
  5. 日志额外的信息,比如打印日志的函数、所在的文件、行号、记录时间

Documentation

Index

Constants

View Source
const (
	CallerTag = "caller"
	LevelTag  = "level"
	MsgTag    = "msg"
	TimeTag   = "time"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// 日志: std, file 多种类型按照逗号隔开
	Out string `toml:"out"`
	// 日志类别: debug, warn, info,error
	Level string `toml:"level"`
	// Out包含file,需要配置
	File *File `toml:"file"`
}

Config 日志配置

func (*Config) GetConfig

func (c *Config) GetConfig() *Config

func (*Config) GetFileConfig

func (c *Config) GetFileConfig() *File

type Field added in v1.0.0

type Field func(IFields)

func FieldInt32 added in v1.0.0

func FieldInt32(key string, val int32) Field

func FieldInt64 added in v1.0.0

func FieldInt64(key string, val int64) Field

func FieldMap added in v1.0.0

func FieldMap(items map[string]interface{}) Field

func FieldString added in v1.0.0

func FieldString(key string, val string) Field

type File

type File struct {
	// 日志文件目录 项目目录
	Path string `toml:"path"`
	// 日志文件默认名称 default.log
	FileName string `toml:"file_name"`
	// 最大文件容量(单位:M),默认:128
	MaxSize int `toml:"max_size"`
	// 最大的备份数量,默认:30
	MaxBackups int `toml:"max_backups"`
	// 最大备份天数,默认:0,没有限制
	MaxAge int `toml:"max_age"`
	// 是否gzip压缩
	Compress bool `toml:"compress"`
}

File 日志文件类别配置

type IData

type IData interface {
	Common(key string, values ...interface{}) IData
	Custom(key string, values ...interface{}) IData
	Map(value map[string]interface{}) IData

	Marshal() []byte
	SetLevel(level Level) IData
	GetLevel() Level
}

func InitData

func InitData() IData

type IFields added in v1.0.0

type IFields interface {
	Set(key string, val interface{}) IFields
	Data() map[string]interface{}
}

func NewFields added in v1.0.0

func NewFields() IFields

type ILogger

type ILogger interface {
	Debugf(msg string, values ...interface{})
	Infof(msg string, values ...interface{})
	Warnf(msg string, values ...interface{})
	Errorf(msg string, values ...interface{})

	Debug(msg string, values ...Field)
	Info(msg string, values ...Field)
	Warn(msg string, values ...Field)
	Error(msg string, values ...Field)
}

type Level

type Level int
const (
	Debug Level = iota
	Info
	Warn
	Error
)

type Option added in v0.0.3

type Option func(*Options)

Option is config option.

func WithSkip added in v0.0.3

func WithSkip(skip int) Option

WithSkip with config source.

type Options added in v0.0.3

type Options struct {
	Skip int
}

func (*Options) GetSkip added in v0.0.3

func (o *Options) GetSkip() int

Directories

Path Synopsis
impl
log

Jump to

Keyboard shortcuts

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