logger

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

README

go-logger

基于zap log的包装,方便引入使用

Documentation

Overview

Package logger...

Description : config 日志配置

Author : go_developer@163.com<白茶清欢>

Date : 2021-01-02 3:07 下午

Package logger...

Description : logger...

Author : go_developer@163.com<白茶清欢>

Date : 2021-01-03 12:58 上午

Package logger...

Description : error 定义日志处理过程中的各种错误

Author : go_developer@163.com<白茶清欢>

Date : 2021-01-02 2:44 下午

Package logger...

Description : logger 日志文件

Author : go_developer@163.com<白茶清欢>

Date : 2021-01-02 5:04 下午

Index

Constants

View Source
const (
	// TimeIntervalTypeMinute 按分钟切割
	TimeIntervalTypeMinute = TimeIntervalType(0)
	// TimeIntervalTypeHour 按小时切割
	TimeIntervalTypeHour = TimeIntervalType(1)
	// TimeIntervalTypeDay 按天切割
	TimeIntervalTypeDay = TimeIntervalType(2)
	// TimeIntervalTypeMonth 按月切割
	TimeIntervalTypeMonth = TimeIntervalType(3)
	// TimeIntervalTypeYear 按年切割
	TimeIntervalTypeYear = TimeIntervalType(4)
)
View Source
const (
	// DefaultDivisionChar 默认的时间格式分隔符
	DefaultDivisionChar = "-"
)

Variables

This section is empty.

Functions

func CreateIOWriteError

func CreateIOWriteError(err error) error

CreateIOWriteError 创建日志实例失败

Author : go_developer@163.com<白茶清欢>

Date : 5:20 下午 2021/1/2

func CreateLogFileError

func CreateLogFileError(err error, logFilePath string) error

CreateLogFileError 创建日志文件失败

Author : go_developer@163.com<白茶清欢>

Date : 2:55 下午 2021/1/2

func CustomTimeIntervalError

func CustomTimeIntervalError() error

CustomTimeIntervalError 自定义日志切割时间间隔错误

Author : go_developer@163.com<白茶清欢>

Date : 4:11 下午 2021/1/2

func DealLogPathError

func DealLogPathError(err error, logPath string) error

DealLogPathError 日志路径处理异常

Author : go_developer@163.com<白茶清欢>

Date : 4:31 下午 2021/1/2

func FormatJson

func FormatJson(src interface{}) string

FormatJson 格式化输出json

Author : go_developer@163.com<白茶清欢>

Date : 1:06 上午 2021/1/3

func GetEncoder

func GetEncoder(option ...SetLoggerOptionFunc) zapcore.Encoder

GetEncoder 获取空中台输出的encoder

Author : go_developer@163.com<白茶清欢>

Date : 6:24 下午 2021/1/2

func LogPathEmptyError

func LogPathEmptyError() error

LogPathEmptyError 日志路径为空

Author : go_developer@163.com<白茶清欢>

Date : 4:03 下午 2021/1/2

func LogSplitTypeError

func LogSplitTypeError(splitType TimeIntervalType) error

LogSplitTypeError 日志切割类型错误

Author : go_developer@163.com<白茶清欢>

Date : 4:50 下午 2021/1/2

func MsTimeEncoder

func MsTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

MsTimeEncoder 毫秒时间格式化方法

Author : go_developer@163.com<白茶清欢>

Date : 8:35 下午 2021/1/3

func NewConsoleLogger

func NewConsoleLogger(loggerLevel zapcore.Level, optionFunc ...SetLoggerOptionFunc) (*zap.Logger, error)

NewConsoleLogger 获取控制台输出的日志实例

Author : go_developer@163.com<白茶清欢>

Date : 8:22 下午 2021/4/17

func NewLogger

func NewLogger(loggerLevel zapcore.Level, splitConfig *RotateLogConfig, optionFunc ...SetLoggerOptionFunc) (*zap.Logger, error)

NewLogger 获取日志实例

Author : go_developer@163.com<白茶清欢>

Date : 5:05 下午 2021/1/2

func SecondTimeEncoder

func SecondTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

SecondTimeEncoder 秒级时间戳格式化

Author : go_developer@163.com<白茶清欢>

Date : 8:34 下午 2021/1/3

Types

type Logger

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

type OptionLogger

type OptionLogger struct {
	UseJsonFormat  bool                    // 日志使用json格式
	MessageKey     string                  // message 字段
	LevelKey       string                  // level 字段
	TimeKey        string                  // 时间字段
	CallerKey      string                  // 记录日志的文件的代码行数
	UseShortCaller bool                    // 使用短的调用文件格式
	TimeEncoder    zapcore.TimeEncoder     // 格式化时间的函数
	EncodeDuration zapcore.DurationEncoder // 原始时间信息
	WithCaller     bool                    // 是否打印文件行号
	WithCallerSkip int                     // 跳过的调用数
	ConsoleOutput  bool                    // 控制台输出
	Encoder        zapcore.Encoder         // 编码函数
}

OptionLogger 日志配置的选项

Author : go_developer@163.com<白茶清欢>

Date : 11:41 下午 2021/1/2

type RotateLogConfig

type RotateLogConfig struct {
	TimeIntervalType TimeIntervalType // 日志切割的时间间隔类型 0 - 小时 1 - 天 2 - 月 3 - 年
	TimeInterval     time.Duration    // 日志切割的时间间隔
	LogPath          string           // 存储日志的路径
	LogFileName      string           // 日志文件名
	DivisionChar     string           // 日志文件拼时间分隔符
	FullLogFormat    string           // 完整的日志格式
	MaxAge           time.Duration    // 日志最长保存时间
}

RotateLogConfig 日志切割的配置

Author : go_developer@163.com<白茶清欢>

Date : 3:08 下午 2021/1/2

func NewRotateLogConfig

func NewRotateLogConfig(logPath string, logFile string, option ...SetRotateLogConfigFunc) (*RotateLogConfig, error)

NewRotateLogConfig 生成日志切割的配置

Author : go_developer@163.com<白茶清欢>

Date : 3:53 下午 2021/1/2

type SetLoggerOptionFunc

type SetLoggerOptionFunc func(o *OptionLogger)

SetLoggerOptionFunc 设置日志配置

func WithCaller

func WithCaller() SetLoggerOptionFunc

WithCaller 打开文件行号记录

func WithCallerKey

func WithCallerKey(callerKey string) SetLoggerOptionFunc

WithCallerKey 设置caller key

Author : go_developer@163.com<白茶清欢>

Date : 12:37 上午 2021/1/3

func WithCallerSkip

func WithCallerSkip(skip int) SetLoggerOptionFunc

WithCallerSkip ...

func WithConsoleOutput

func WithConsoleOutput() SetLoggerOptionFunc

WithConsoleOutput 日志控制台输出

func WithEncodeDuration

func WithEncodeDuration(encoder zapcore.DurationEncoder) SetLoggerOptionFunc

WithEncodeDuration 原始时间

Author : go_developer@163.com<白茶清欢>

Date : 12:42 上午 2021/1/3

func WithEncoder

func WithEncoder(encoder zapcore.Encoder) SetLoggerOptionFunc

WithEncoder ...

func WithLevelKey

func WithLevelKey(levelKey string) SetLoggerOptionFunc

WithLevelKey 设置level key

Author : go_developer@163.com<白茶清欢>

Date : 12:33 上午 2021/1/3

func WithMessageKey

func WithMessageKey(messageKey string) SetLoggerOptionFunc

WithMessageKey 使用message key

Author : go_developer@163.com<白茶清欢>

Date : 12:32 上午 2021/1/3

func WithShortCaller

func WithShortCaller(useShortCaller bool) SetLoggerOptionFunc

WithShortCaller 是否使用短caller格式

Author : go_developer@163.com<白茶清欢>

Date : 12:39 上午 2021/1/3

func WithTimeEncoder

func WithTimeEncoder(encoder zapcore.TimeEncoder) SetLoggerOptionFunc

WithTimeEncoder 设置格式化时间方法

Author : go_developer@163.com<白茶清欢>

Date : 12:41 上午 2021/1/3

func WithTimeKey

func WithTimeKey(timeKey string) SetLoggerOptionFunc

WithTimeKey 设置time key ...

Author : go_developer@163.com<白茶清欢>

Date : 12:34 上午 2021/1/3

func WithUseJsonFormat

func WithUseJsonFormat(isJsonFormat bool) SetLoggerOptionFunc

WithUseJsonFormat 日志是否使用json格式数据

Author : go_developer@163.com<白茶清欢>

Date : 12:30 上午 2021/1/3

type SetRotateLogConfigFunc

type SetRotateLogConfigFunc func(rlc *RotateLogConfig)

SetRotateLogConfigOption 设置日志切割的选项

Author : go_developer@163.com<白茶清欢>

Date : 3:13 下午 2021/1/2

func WithDivisionChar

func WithDivisionChar(divisionChar string) SetRotateLogConfigFunc

WithDivisionChar 设置分隔符

Author : go_developer@163.com<白茶清欢>

Date : 3:49 下午 2021/1/2

func WithMaxAge

func WithMaxAge(maxAge time.Duration) SetRotateLogConfigFunc

WithMaxAge 设置日志保存时间

Author : go_developer@163.com<白茶清欢>

Date : 5:03 下午 2021/1/2

func WithTimeIntervalType

func WithTimeIntervalType(timeIntervalType TimeIntervalType) SetRotateLogConfigFunc

WithTimeIntervalType 设置日志切割时间间隔

Author : go_developer@163.com<白茶清欢>

Date : 3:34 下午 2021/1/2

type TimeIntervalType

type TimeIntervalType uint

TimeIntervalType 日志时间间隔类型

Directories

Path Synopsis
Package wrapper...
Package wrapper...

Jump to

Keyboard shortcuts

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