log

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package log

Package log 日志记录器

基于zap的日志库 提供zap可定制的日志类

初始化日志类 logger = log.New() logger.Info() logger.Warn() logger.Error()

默认内置了常用的日志类 prodLog = log.Default() devLog = log.Dev() 创建原生Logger而不是Sugar log.NewZap() 基于zapCore创建 zap.NewCore() 注意:带日志绕接的日志类只能通过core创建

Package log

Package log

Package log

Package log

Package log

Index

Constants

View Source
const EncodingConsole = "console"
View Source
const EncodingJSON = "json"

Variables

View Source
var DefaultOption = Option{
	Development:  false,
	Level:        InfoLevel,
	StackTrace:   false,
	Encoding:     EncodingJSON,
	Output:       DefaultOutput,
	EncodeConfig: zapEncodeConfig,
}

DefaultOption 默认配置

View Source
var DefaultOutput = []string{"stderr"}

DefaultOutput 默认会记录到stderr fatal错误不会被记录

View Source
var DefaultRotateOption = RotateOption{
	MaxSize:    10,
	MaxAge:     30,
	MaxBackups: 10,
	LocalTime:  true,
	Compress:   false,
}
View Source
var DevOption = Option{
	Development:  true,
	Level:        DebugLevel,
	StackTrace:   true,
	Encoding:     EncodingJSON,
	Output:       DefaultOutput,
	EncodeConfig: zapEncodeConfig,
}

Functions

func ConvertConfig

func ConvertConfig(op Option) zap.Config

ConvertConfig 从fushin option转为zap config

func DefaultEncodeConfig

func DefaultEncodeConfig() zapcore.EncoderConfig

func ModuleName

func ModuleName() string

func NewZap

func NewZap(c zap.Config, op ...zap.Option) (*zap.Logger, error)

NewZap 不使用sugar而是使用原生的zap logger

Types

type Level

type Level int8
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel Level = iota - 1
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

type Logger

type Logger struct {
	Name   string
	Option Option
	Sync   bool
	// contains filtered or unexported fields
}

func Default

func Default(name string) *Logger

func Dev

func Dev(name string) *Logger

func New

func New(name string, op Option) *Logger

New 新建日志

func NewCore added in v1.1.5

func NewCore(name string, op Option) *Logger

NewCore 基于core创建

func NewCoreRotate added in v1.1.13

func NewCoreRotate(name string, op Option) *Logger

NewCoreRotate create a coreLogger with rotate

func NewCoreStd added in v1.1.13

func NewCoreStd(name string, op Option) *Logger

NewCoreStd create a coreLogger with os.std

func Raw

func Raw(name string, c zap.Config, op ...zap.Option) Logger

Raw 使用zap原生配置创建

func (Logger) Error

func (l Logger) Error(v ...interface{})

func (Logger) ErrorF

func (l Logger) ErrorF(fmtStr string, v ...interface{})

func (Logger) Info

func (l Logger) Info(v ...interface{})

func (Logger) InfoF

func (l Logger) InfoF(fmtStr string, v ...interface{})

func (*Logger) Init

func (l *Logger) Init() error

Init 从Logger内置的参数新建日志构建logger

func (Logger) Warn

func (l Logger) Warn(v ...interface{})

func (Logger) WarnF

func (l Logger) WarnF(fmtStr string, v ...interface{})

type LoggerInterface added in v1.0.5

type LoggerInterface interface {
	Info(v ...interface{})
	Warn(v ...interface{})
	Error(v ...interface{})
	InfoF(fmt string, v ...interface{})
	WarnF(fmt string, v ...interface{})
	ErrorF(fmt string, v ...interface{})
}

type LoggerPanic added in v1.0.5

type LoggerPanic interface {
	Panic(v ...interface{})
	PanicF(fmt string, v ...interface{})
}

type Option

type Option struct {
	Development  bool
	Level        Level
	EnableCaller bool
	StackTrace   bool
	Encoding     string
	Output       []string
	EncodeConfig zapcore.EncoderConfig // 原生的zap配置
	RotateOption RotateOption
}

Option 日志的配置项

type RotateOption added in v1.1.5

type RotateOption struct {
	MaxSize    int // 单位mb
	MaxAge     int // 单位天
	MaxBackups int // 单位个
	LocalTime  bool
	Compress   bool
}

Directories

Path Synopsis
Package private 默认的内置日志
Package private 默认的内置日志

Jump to

Keyboard shortcuts

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