Documentation ¶
Index ¶
- Constants
- Variables
- func Any(key string, value interface{}) zap.Field
- func ByteString(key string, val []byte) zap.Field
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func ErrorField(err error) zap.Field
- func Fatal(msg string, fields ...zap.Field)
- func Info(msg string, fields ...zap.Field)
- func InfoField(v interface{}) zap.Field
- func NewLog(config *LogConfig) *zap.Logger
- func RotatePeriod(l *lumberjack.Logger, periodSecond int64)
- func SetGlobalLog(appName string, prod bool, opts ...OptionFunc)
- func String(key string, value string) zap.Field
- func Warn(msg string, fields ...zap.Field)
- func ZapToLogrusLevel(zapLevel zapcore.Level) logrus.Level
- type FormatEnum
- type FormatTime
- type LevelEnum
- type LogConfig
- type LogHook
- type LogrusToZapHook
- type OptionFunc
- func WithAppNameOption(v string) OptionFunc
- func WithDirOption(v string) OptionFunc
- func WithFormatOption(v FormatEnum) OptionFunc
- func WithHooksOption(hooks ...LogHook) OptionFunc
- func WithLevelOption(v LevelEnum) OptionFunc
- func WithLocalTimeOption(v bool) OptionFunc
- func WithMaxBackupsOption(v int) OptionFunc
- func WithMaxSizeOption(v int) OptionFunc
- func WithMultiWriteOption(v bool) OptionFunc
- func WithRotatePeriodSecondOption(v int64) OptionFunc
Constants ¶
const ( FormatEnumJSON FormatEnum = "json" FormatEnumConsole FormatEnum = "console" DefaultRotatePeriodSecond int64 = 60 * 60 * 24 // 一天 )
Variables ¶
var ( LevelEnumDebug = zap.NewAtomicLevelAt(zapcore.DebugLevel) LevelEnumInfo = zap.NewAtomicLevelAt(zapcore.InfoLevel) )
Functions ¶
func ByteString ¶
ByteString 会把[]byte转成string 注意 Any() 会把[]byte转成 binary
func Debug ¶
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 ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func ErrorField ¶
func Fatal ¶
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 ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func SetGlobalLog ¶
func SetGlobalLog(appName string, prod bool, opts ...OptionFunc)
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 ¶
type LogrusToZapHook ¶
type LogrusToZapHook struct {
// contains filtered or unexported fields
}
LogrusToZapHook 是一个 logrus Hook,用于将 logrus 日志重定向到 zap
func NewLogrusToZapHook ¶
func NewLogrusToZapHook(zapLogger *zap.Logger) *LogrusToZapHook
NewLogrusToZapHook 创建一个新的 LogrusToZapHook
func (*LogrusToZapHook) Fire ¶
func (h *LogrusToZapHook) Fire(entry *logrus.Entry) error
Fire 将 logrus 的日志条目重定向到 zap
func (*LogrusToZapHook) Levels ¶
func (h *LogrusToZapHook) Levels() []logrus.Level
Levels 返回 logrus 支持的所有日志级别
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 WithMaxBackupsOption ¶
func WithMaxBackupsOption(v int) OptionFunc
func WithMaxSizeOption ¶
func WithMaxSizeOption(v int) OptionFunc
func WithMultiWriteOption ¶
func WithMultiWriteOption(v bool) OptionFunc
func WithRotatePeriodSecondOption ¶
func WithRotatePeriodSecondOption(v int64) OptionFunc