klog

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// trace 日志前缀标识(放在[]zap.Field的第一个位置提高效率)
	TopicType = "_tp"
	// 业务日志名字
	LogNameServer = "server"
	// access 日志文件名字
	LogNameAccess = "access"
	// module 日志文件名字
	LogNameModule = "module"
)
View Source
const (
	ContextKeyRequestID = "requestId"
	ContextKeyLogID     = "logID"
	ContextKeyNoLog     = "_no_log"
	ContextKeyUri       = "_uri"
)

util key

View Source
const (
	TraceHeaderKey      = "Uber-Trace-Id"
	LogIDHeaderKey      = "X_BD_LOGID"
	LogIDHeaderKeyLower = "x_bd_logid"
)

header key

Variables

View Source
var (
	Binary = zap.Binary
	Bool   = zap.Bool

	ByteString = zap.ByteString
	String     = zap.String
	Strings    = zap.Strings

	Float64 = zap.Float64
	Float32 = zap.Float32

	Int   = zap.Int
	Int64 = zap.Int64
	Int32 = zap.Int32
	Int16 = zap.Int16
	Int8  = zap.Int8

	Uint   = zap.Uint
	Uint64 = zap.Uint64
	Uint32 = zap.Uint32

	Reflect   = zap.Reflect
	Namespace = zap.Namespace
	Duration  = zap.Duration
	Object    = zap.Object
	Any       = zap.Any
	Skip      = zap.Skip()
)
View Source
var (
	SugaredLogger *zap.SugaredLogger
	ZapLogger     *zap.Logger
)

Functions

func AddNotice

func AddNotice(ctx *gin.Context, key string, val interface{})

用户自定义Notice

func CloseLogger

func CloseLogger()

func Debug

func Debug(ctx *gin.Context, args ...interface{})

提供给业务使用的server log 日志打印方法

func DebugLogger

func DebugLogger(ctx *gin.Context, msg string, fields ...zap.Field)

func Debugf

func Debugf(ctx *gin.Context, format string, args ...interface{})

func Error

func Error(ctx *gin.Context, args ...interface{})

func ErrorLogger

func ErrorLogger(ctx *gin.Context, msg string, fields ...zap.Field)

func Errorf

func Errorf(ctx *gin.Context, format string, args ...interface{})

func Fatal

func Fatal(ctx *gin.Context, args ...interface{})

func FatalLogger

func FatalLogger(ctx *gin.Context, msg string, fields ...zap.Field)

func Fatalf

func Fatalf(ctx *gin.Context, format string, args ...interface{})

func GetCustomerKeyValue

func GetCustomerKeyValue(ctx *gin.Context) map[string]interface{}

获得所有用户自定义的Notice

func GetLogger

func GetLogger() (s *zap.SugaredLogger)

GetLogger 获得一个新的logger 会把日志打印到 name.log 中,不建议业务使用 deprecated

func GetRequestID

func GetRequestID(ctx *gin.Context) string

func GetZapLogger

func GetZapLogger() (l *zap.Logger)

func Info

func Info(ctx *gin.Context, args ...interface{})

func InfoLogger

func InfoLogger(ctx *gin.Context, msg string, fields ...zap.Field)

func Infof

func Infof(ctx *gin.Context, format string, args ...interface{})

func InitLog

func InitLog(conf LogConfig) *zap.SugaredLogger

func NewCsseJSONEncoder

func NewCsseJSONEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder

func NewEntry

func NewEntry(s *zap.SugaredLogger) *entry

func NoLog

func NoLog(ctx *gin.Context) bool

func Panic

func Panic(ctx *gin.Context, args ...interface{})

func PanicLogger

func PanicLogger(ctx *gin.Context, msg string, fields ...zap.Field)

func Panicf

func Panicf(ctx *gin.Context, format string, args ...interface{})

func PrintNotice

func PrintNotice(ctx *gin.Context)

server.log 中打印出用户自定义Notice

func RegisterCsseJSONEncoder

func RegisterCsseJSONEncoder() error

RegisterCsseJSONEncoder registers a special jsonEncoder under "csse-json" name.

func SetNoLogFlag

func SetNoLogFlag(ctx *gin.Context)

func Warn

func Warn(ctx *gin.Context, args ...interface{})

func WarnLogger

func WarnLogger(ctx *gin.Context, msg string, fields ...zap.Field)

func Warnf

func Warnf(ctx *gin.Context, format string, args ...interface{})

Types

type Buffer

type Buffer struct {
	Switch        bool          `yaml:"switch"`
	Size          int           `yaml:"size"`
	FlushInterval time.Duration `yaml:"flushInterval"`
}

type Field

type Field = zap.Field

type Fields

type Fields map[string]interface{}

-------------避免用户改动过大,以下为封装的之前的Entry打印field的方法----------

type LogConfig

type LogConfig struct {
	Level    string `yaml:"level"`
	Stdout   bool   `yaml:"stdout"`
	Log2File bool   `yaml:"log2file"`
	Path     string `yaml:"path"`
	Rotate   Rotate `yaml:"rotate"`
	Buffer   Buffer `yaml:"buffer"`
}

日志切分相关的log配置,仅虚拟机线上支持

type Rotate

type Rotate struct {
	Switch bool   `yaml:"switch"`
	Unit   string `yaml:"unit"`
	Count  int    `yaml:"count"`
}

对用户暴露的log配置

type TimeFileLogWriter

type TimeFileLogWriter struct {
	// contains filtered or unexported fields
}

This log writer sends output to a file

func NewTimeFileLogWriter

func NewTimeFileLogWriter(fName string) *TimeFileLogWriter

func (*TimeFileLogWriter) Write

func (w *TimeFileLogWriter) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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