log

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

README

log

  • log是对zap.Log的封装
  • 支持日志文件按时间分割和按大小分割
  • 支持hook操作
  • 日志文件建议统一写在logs目录下

Documentation

Index

Constants

View Source
const (
	FormatEnumJSON    FormatEnum = "json"
	FormatEnumConsole FormatEnum = "console"

	DefaultRotatePeriodSecond int64 = 60 * 60 * 24 // 一天
)

Variables

Functions

func Any

func Any(key string, value interface{}) zap.Field

func ByteString

func ByteString(key string, val []byte) zap.Field

ByteString 会把[]byte转成string 注意 Any() 会把[]byte转成 binary

func Debug

func Debug(msg string, fields ...zap.Field)

Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func Error

func Error(msg string, fields ...zap.Field)

func ErrorField

func ErrorField(err error) zap.Field

func Fatal

func Fatal(msg string, fields ...zap.Field)

Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Info

func Info(msg string, fields ...zap.Field)

func InfoField

func InfoField(v interface{}) zap.Field

func Level2FileName

func Level2FileName(level zap.AtomicLevel) string

日志级别转化不同文件输出

func LogRotatePeriod

func LogRotatePeriod(log *lumberjack.Logger, periodSecond int64)

func NewLog

func NewLog(config *LogConfig) *zap.Logger

func SetGlobalLog

func SetGlobalLog(appName string, prod bool, opts ...OptionFunc)

func String

func String(key string, value string) zap.Field

func Warn

func Warn(msg string, fields ...zap.Field)

Types

type FormatEnum

type FormatEnum string

type FormatTime

type FormatTime = zapcore.TimeEncoder

type LevelEnum

type LevelEnum = zap.AtomicLevel

type LogConfig

type LogConfig struct {

	// hook
	Hooks []LogHook
	// contains filtered or unexported fields
}

func DefaultLogConfig

func DefaultLogConfig() *LogConfig

默认开发环境

func ProdLogConfig

func ProdLogConfig(appName string) *LogConfig

线上环境

type LogHook

type LogHook interface {
	DoHook(zapcore.Entry) error
}

type OptionFunc

type OptionFunc func(*LogConfig)

func WithAppNameOption

func WithAppNameOption(v string) OptionFunc

func WithDirOption

func WithDirOption(v string) OptionFunc

func WithFormatOption

func WithFormatOption(v FormatEnum) OptionFunc

func WithHooksOption

func WithHooksOption(hooks ...LogHook) OptionFunc

func WithLevelOption

func WithLevelOption(v LevelEnum) OptionFunc

func WithLocalTimeOption

func WithLocalTimeOption(v bool) OptionFunc

func WithMaxSizeOption

func WithMaxSizeOption(v int) OptionFunc

func WithMultiWriteOption

func WithMultiWriteOption(v bool) OptionFunc

func WithRotatePeriodSecondOption

func WithRotatePeriodSecondOption(v int64) OptionFunc

Jump to

Keyboard shortcuts

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