jlog

package
v0.0.0-...-3f91146 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HolderLevel        = "${level}"
	DefaultFilePattern = "j-%Y-%m-%d.log"
)

Variables

View Source
var Zap = new(_zap)

Functions

This section is empty.

Types

type KeyLogConfig

type KeyLogConfig struct {
	TimeKey       string
	LevelKey      string
	NameKey       string
	CallerKey     string
	FunctionKey   string
	MessageKey    string
	StacktraceKey string
}

type LogConfig

type LogConfig struct {
	// 级别
	Level string `mapstructure:"level,omitempty" json:"level,omitempty" yaml:"level,omitempty"`

	// 日志文件夹
	Dir string `mapstructure:"dir,omitempty" json:"dir,omitempty"  yaml:"dir,omitempty" toml:"dir,omitempty"`
	// 日志文件路径(模式),可以用多级路径,拼接在 Dir 后面。
	// 可用时间格式、事件格式,如 %Y-%m-%d/${level}.log 表示 按日期和级别分割
	FilePattern string `mapstructure:"filePattern,omitempty" json:"filePattern,omitempty" yaml:"filePattern,omitempty" toml:"filePattern,omitempty"`
	// 日志留存时间(天)
	MaxAge int `mapstructure:"maxAge,omitempty" json:"maxAge,omitempty" yaml:"maxAge,omitempty" toml:"maxAge,omitempty"`

	// 输出格式 console(默认) 或者 json
	Format string `mapstructure:"format,omitempty" json:"format,omitempty" yaml:"format,omitempty" toml:"format,omitempty"`

	// 编码级,可用值为:
	//  color
	//  capital
	//  capitalColor
	EncodeLevel string `mapstructure:"encodeLevel,omitempty" json:"encodeLevel,omitempty" yaml:"encodeLevel,omitempty" toml:"encodeLevel,omitempty"`

	// 自定义特殊字段的 key,主要是用在 json 格式中
	LogKey *KeyLogConfig `mapstructure:"logKey,omitempty" json:"logKey,omitempty" yaml:"logKey,omitempty" toml:"logKey,omitempty"`

	// 显示行号
	ShowLine bool `mapstructure:"showLine,omitempty" json:"showLine,omitempty" yaml:"showLine,omitempty" toml:"showLine,omitempty"`
	// 输出到文件同时输出到控制台
	AppendConsole bool `` /* 131-byte string literal not displayed */
}

func (*LogConfig) FixDefault

func (c *LogConfig) FixDefault()

FixDefault 设置默认值

func (*LogConfig) GetLogPath

func (c *LogConfig) GetLogPath() string

GetLogPath 获取日志文件路径,如果没有配置,则返回空。如果只配置了目录,则按日期拆分

func (*LogConfig) ISFileSplitByEvent

func (c *LogConfig) ISFileSplitByEvent() bool

ISFileSplitByEvent 是否按事件分割文件

func (*LogConfig) IsFileEnabled

func (c *LogConfig) IsFileEnabled() bool

IsFileEnabled 是否启用文件输出

func (*LogConfig) TransportLevel

func (c *LogConfig) TransportLevel() zapcore.Level

TransportLevel 获取日志级别,默认是 info

func (*LogConfig) ZapEncodeLevel

func (c *LogConfig) ZapEncodeLevel() zapcore.LevelEncoder

ZapEncodeLevel "color": 小写编码器带颜色 "capital": 大写编码器 "capitalColor": 大写编码器带颜色 小写编码器(默认)

type Logger

type Logger zap.Logger

func (*Logger) ForTask

func (L *Logger) ForTask(name string) *Logger

Jump to

Keyboard shortcuts

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