log

package
v0.0.0-...-49bf833 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 6 Imported by: 0

README

  • 使用定制化日志包, 方便扩展以及统一日志格式

    • 创建 zap.Logger 的自定义 Logger 对象
    • 编写创建函数,创建 zapLogger 对象
    • 创建 *zap.Logger 对象
    • 实现日志接口
  • 日志包为 github.com/daz-3ux/dBlog/internal/pkg/log

    • 日志包使用 zap 库,在 zap 库基础上进行了一层封装
    • 拥有 2 类 zapLogger 对象
      • 全局对象
        • 使用类似 log.Infow() 的方式进行调用
        • Init(opts *Options) 初始化全局对象
      • 局部对象
        • 可以传入不同参数,创建一个自定义的 *zapLogger 对象
        • NewLogger(opts *Options) *zapLogger 创建一个自定义的 *zapLogger
    • 通过 Options 结构体对日志系统进行配置
      • 可以通过 NewOptions() 创建一个默认的 *Options 对象
      • 自定义配置文件存放于 yaml 之中,通过 viper 读取日志配置
  • zap

    • zap 是一个高性能的日志库,在性能上远超标准库 log 包
    • zap 有两种日志记录模式:
      • SugaredLogger
        • 支持结构化以及printf风格的日志记录
      • Logger
        • 只支持强类型的结构化日志记录
        • 性能甚至高于SugaredLogger

Documentation

Overview

Package log is a log package used by dazBlog project

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func C

func C(ctx context.Context) *zapLogger

C extracts relevant key-value pairs from the incoming context and adds them to the structured logs of the zap.Logger.

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

Debugw print debug level log

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

Errorw print error level log

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

Fatalw print fatal level log

func Infow

func Infow(msg string, keysAndValues ...interface{})

Infow print info level log

func Init

func Init(opts *Options)

Init initializes the global logger with the given options

func NewLogger

func NewLogger(opts *Options) *zapLogger

NewLogger creates a new logger with the given options

func Panicw

func Panicw(msg string, keysAndValues ...interface{})

Panicw print panic level log

func Sync

func Sync()

Sync flushes all buffered logs into the disk main function should call this function before exit

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw print warn level log

Types

type Logger

type Logger interface {
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
	Sync()
}

Logger define dBlog's logger interface

type Options

type Options struct {
	// if enabled, the log will display the file and line num of the calling log
	DisableCaller bool
	// if enabled, will print stack info for panic and higher log level
	DisableStacktrace bool
	// log level: debug, info , warn, error, dpanic, panic, fatal
	Level string
	// log format: console, json
	Format string
	// specify log output path
	OutputPaths []string
}

Options the options for the logger

func NewOptions

func NewOptions() *Options

NewOptions creates an Options object with default parameters

Jump to

Keyboard shortcuts

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