logger

package
v1.12.22 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT, MIT Imports: 7 Imported by: 8

README

golang logger

基于uber zap封装而成的logger模块,可用于go应用中记录操作日志

Documentation

Overview

logger 基于zap日志库,进行封装的logger库 支持日志自动切割

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress added in v1.9.3

func Compress(b bool)

Compress 日志是否压缩

func DPanic

func DPanic(msg string, options map[string]interface{})

DPanic 调试模式下的panic,程序不退出,继续运行

func Debug

func Debug(msg string, options map[string]interface{})

Debug debug日志直接输出到终端

func Error

func Error(msg string, options map[string]interface{})

Error 错误类型的日志

func Fatal

func Fatal(msg string, options map[string]interface{})

Fatal 抛出致命错误,然后退出程序

func Info

func Info(msg string, options map[string]interface{})

Info info级别日志

func InitLogger

func InitLogger(skip ...int)

* InitLogger 初始化fLogger句柄,skip指定显示文件名和行号的层级 skip 大于0会调用zap.AddCallerSkip Caller(skip int)函数可以返回当前goroutine调用栈中的文件名,行号,函数信息等 参数skip表示表示返回的栈帧的层次,0表示runtime.Caller的调用者,依次往上推导 而golang 标准库中runtime.Caller(2) 返回当前goroutine调用栈中的文件名,行号,函数信息 如果直接调用这个logger库中的Info,Error等方法,这里skip=1 如果基于logger进行日志再进行封装,这个skip=2,依次类推 zap底层源码从v1.14版本之后,logger.go#260 check func check must always be called directly by a method in the Logger interface (e.g., Check, Info, Fatal). const callerSkipOffset = 2 这里的callerSkipOffset默认是2,所以这里InitLogger skip需要初始化为1

func LogLevel

func LogLevel(lvl string)

LogLevel 日志级别

func LogSugar

func LogSugar(skip ...int) *zap.SugaredLogger

LogSugar sugar语法糖,支持简单的msg信息打印 支持Debug,Info,Error,Panic,Warn,Fatal等方法

func MaxAge

func MaxAge(n int)

MaxAge 日志保留时间

func MaxSize

func MaxSize(n int)

MaxSize 日志大小 mb

func Panic

func Panic(msg string, options map[string]interface{})

Panic 下面的panic,fatal一般不建议使用,除非不可恢复的panic或致命错误程序必须退出 抛出panic的时候,先记录日志,然后执行panic,退出当前goroutine

func Recover added in v1.1.9

func Recover()

Recover 异常捕获处理,对于异常或者panic进行捕获处理,记录到日志中,方便定位问题

func SetLogDir added in v1.1.8

func SetLogDir(dir string)

SetLogDir 日志存放目录

func SetLogFile

func SetLogFile(name string)

SetLogFile 设置日志文件路径,如果日志文件不存在zap会自动创建文件

func TraceFileLine added in v1.9.3

func TraceFileLine(b bool)

TraceFileLine 是否开启记录文件名和行数

func Warn

func Warn(msg string, options map[string]interface{})

Warn 警告类型的日志

Types

This section is empty.

Jump to

Keyboard shortcuts

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