logx

package module
v1.0.3 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: 7 Imported by: 1

README

logx

基于uber zap封装的日志类

go version >=1.18

使用

package main

import (
    "github.com/xmapst/logx"
)

func main()  {
    // 直接使用, 内容将直接输出到控制台
    logx.Infoln("日志内容")
	
    // 设置写入文件
    logx.SetupLogger("logx.log")
    logx.Infof("日志内容")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultConfig 日志配置
	DefaultConfig = zapcore.EncoderConfig{
		CallerKey:     "line",
		LevelKey:      "level",
		MessageKey:    "message",
		TimeKey:       "time",
		StacktraceKey: "stacktrace",
		LineEnding:    zapcore.DefaultLineEnding,
		EncodeTime:    zapcore.ISO8601TimeEncoder,
		EncodeLevel: func(level zapcore.Level, encoder zapcore.PrimitiveArrayEncoder) {
			encoder.AppendString(firstUpper(level.String()))
		},
		EncodeCaller: func(caller zapcore.EntryCaller, encoder zapcore.PrimitiveArrayEncoder) {
			encoder.AppendString("[" + caller.TrimmedPath() + "]")
		},
		EncodeDuration:   zapcore.SecondsDurationEncoder,
		EncodeName:       zapcore.FullNameEncoder,
		ConsoleSeparator: " ",
	}
)

Functions

func CloseLogger

func CloseLogger()

CloseLogger 系统运行结束时,将日志落盘;

func DPanic

func DPanic(args ...interface{})

DPanic 输出"DPanic"级别日志信息,但不引发程序Panic

func DPanicf

func DPanicf(template string, args ...interface{})

DPanicf 输出格式化的"DPanic"级别日志信息,但不引发程序Panic

func DPanicln

func DPanicln(args ...interface{})

func DPanicw

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

DPanicw 输出定制化的"Panic"级别日志信息,但不引发程序Panic()

func DPanicx

func DPanicx(msg string, fields ...zapcore.Field)

DPanicx 以zapfield方式,极速输出定制化的"Panic"级别日志信息,但不引发程序Panic()

func Debug

func Debug(args ...interface{})

Debug 输出"Debug"级别日志信息;

func Debugf

func Debugf(template string, args ...interface{})

Debugf 输出格式化的"Debug"级别日志信息;

func Debugln

func Debugln(args ...interface{})

func Debugw

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

Debugw 输出定制化的"Debug"级别日志信息;

func Debugx

func Debugx(msg string, fields ...zapcore.Field)

Debugx 以zapfield方式,极速输出定制化的"Debug"级别日志信息;

func Error

func Error(args ...interface{})

Error 输出"Error"级别日志信息;

func Errorf

func Errorf(template string, args ...interface{})

Errorf 输出格式化的"Error"级别日志信息;

func Errorln

func Errorln(args ...interface{})

func Errorw

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

Errorw 输出定制化的"Error"级别日志信息;

func Errorx

func Errorx(msg string, fields ...zapcore.Field)

Errorx 以zapfield方式,极速输出定制化的"Error"级别日志信息;

func Fatal

func Fatal(args ...interface{})

Fatal 输出"Fatal"级别日志信息,并使程序退出(os.Exit(1);

func Fatalf

func Fatalf(template string, args ...interface{})

Fatalf 输出格式化的"Fatal"级别日志信息,并使程序退出(os.Exit(1);

func Fatalln

func Fatalln(args ...interface{})

func Fatalw

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

Fatalw 输出定制化的"Fatal"级别日志信息,并使程序退出(os.Exit(1);

func Fatalx

func Fatalx(msg string, fields ...zapcore.Field)

Fatalx 以zapfield方式,极速输出定制化的"Fatal"级别日志信息,并使程序退出(os.Exit(1);

func Info

func Info(args ...interface{})

Info 输出"Info"级别日志信息;

func Infof

func Infof(template string, args ...interface{})

Infof 输出格式化的"Info"级别日志信息;

func Infoln

func Infoln(args ...interface{})

func Infow

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

InfoW 输出定制化的"Info"级别日志信息;

func Infox

func Infox(msg string, fields ...zapcore.Field)

Infox 以zapfield方式,极速输出定制化的"Info"级别日志信息;

func Panic

func Panic(args ...interface{})

Panic 输出"Panic"级别日志信息,并引发程序Panic;

func Panicf

func Panicf(template string, args ...interface{})

Panicf 输出格式化的"Panic"级别日志信息,并引发程序Panic;

func Panicln

func Panicln(args ...interface{})

func Panicw

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

Panicw 输出定制化的"Panic"级别日志信息,并引发程序Panic;

func Panicx

func Panicx(msg string, fields ...zapcore.Field)

Panicx 以zapfield方式,极速输出定制化的"Panic"级别日志信息,并引发程序Panic;

func SetLevel

func SetLevel(l zapcore.Level)

func SetupConsoleLogger added in v1.0.2

func SetupConsoleLogger(logfile string, options ...zap.Option)

SetupConsoleLogger 配置日志记录器

func SetupJSONLogger added in v1.0.2

func SetupJSONLogger(logfile string, options ...zap.Option)

SetupJSONLogger 配置日志记录器

func SetupLogger

func SetupLogger(logfile string, encoder zapcore.Encoder, options ...zap.Option)

func Warn

func Warn(args ...interface{})

Warn 输出"Warn"级别日志信息;

func Warnf

func Warnf(template string, args ...interface{})

Warnf 输出格式化的"Warn"级别日志信息;

func Warning

func Warning(args ...interface{})

Warning 输出"Warn"级别日志信息;

func Warningf

func Warningf(template string, args ...interface{})

Warningf 输出格式化的"Warn"级别日志信息;

func Warningln

func Warningln(args ...interface{})

func Warningw

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

Warningw 输出定制化的"Warn"级别日志信息;

func Warningx

func Warningx(msg string, fields ...zapcore.Field)

Warningx 以zapfield方式,极速输出定制化的"Warn"级别日志信息;

func Warnln

func Warnln(args ...interface{})

func Warnw

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

Warnw 输出定制化的"Warn"级别日志信息;

func Warnx

func Warnx(msg string, fields ...zapcore.Field)

Warnx 以zapfield方式,极速输出定制化的"Warn"级别日志信息;

Types

type Logger

type Logger interface {
	Print(...interface{})
	Println(...interface{})
	Printf(string, ...interface{})
	Printw(string, ...interface{})
	Printx(string, ...zapcore.Field)

	Debug(...interface{})
	Debugln(...interface{})
	Debugf(string, ...interface{})
	Debugw(string, ...interface{})
	Debugx(string, ...zapcore.Field)

	Info(...interface{})
	Infoln(...interface{})
	Infof(string, ...interface{})
	Infow(string, ...interface{})
	Infox(string, ...zapcore.Field)

	Warn(...interface{})
	Warnln(...interface{})
	Warnf(string, ...interface{})
	Warnw(string, ...interface{})
	Warnx(string, ...zapcore.Field)

	Warning(...interface{})
	Warningln(...interface{})
	Warningf(string, ...interface{})
	Warningw(string, ...interface{})
	Warningx(string, ...zapcore.Field)

	Error(...interface{})
	Errorln(...interface{})
	Errorf(string, ...interface{})
	Errorw(string, ...interface{})
	Errorx(string, ...zapcore.Field)

	Panic(...interface{})
	Panicln(...interface{})
	Panicf(string, ...interface{})
	Panicw(string, ...interface{})
	Panicx(string, ...zapcore.Field)

	Fatal(...interface{})
	Fatalln(...interface{})
	Fatalf(string, ...interface{})
	Fatalw(string, ...interface{})
	Fatalx(string, ...zapcore.Field)

	DPanic(...interface{})
	DPanicln(...interface{})
	DPanicf(string, ...interface{})
	DPanicw(string, ...interface{})
	DPanicx(string, ...zapcore.Field)

	GetSubLogger() Logger
	GetSubLoggerWithKeyValue(map[string]string) Logger
	GetSubLoggerWithOption(...zap.Option) Logger
}

func GetSubLogger

func GetSubLogger() Logger

GetSubLogger 获取一个子logger

func GetSubLoggerWithKeyValue

func GetSubLoggerWithKeyValue(keysAndValues map[string]string) Logger

GetSubLoggerWithKeyValue 使用指定的key/value,获取一个带有输出key/value内容的子logger

func GetSubLoggerWithOption

func GetSubLoggerWithOption(opts ...zap.Option) Logger

Jump to

Keyboard shortcuts

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