nlog

package
v0.0.5-beta2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TopicType     = "_tp"
	LogNameServer = "server"
	LogNameAccess = "access"
	LogNameModule = "module"
)
View Source
const (
	ContextKeyRequestID     = "requestId"
	ContextKeyLogID         = "logId"
	ContextKeyNoLog         = "_no_log"
	ContextKeyUri           = "_uri"
	ContextKeyUserID        = "userId"
	ContextKeyTenantID      = "tenantId"
	ContextKeyMachineID     = "machineId"
	ContextKeyExternalAddr  = "externalAddr"
	ContextKeyUserAuthGroup = "userAuthGroup"
)

util key

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

header key

View Source
const ContextValAllAuthGroup = "-1" // 所有分组权限都有
View Source
const ContextValNoAuthGroup = "-2" // 所有分组权限都没有
View Source
const (
	StartTime = "startTime"
)

rpcx 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 context.Context, key string, val interface{})

用户自定义Notice

func CloseLogger

func CloseLogger()

func Debug

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

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

func DebugLogger

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

func Debugf

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

func Error

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

func ErrorLogger

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

func Errorf

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

func Fatal

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

func FatalLogger

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

func Fatalf

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

func GetCustomKV

func GetCustomKV(ctx context.Context, key string) string

func GetCustomerKeyValue

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

获得所有用户自定义的Notice

func GetExternalAddress

func GetExternalAddress(ctx context.Context) string

func GetKeyURI

func GetKeyURI(ctx context.Context) string

func GetLogID

func GetLogID(ctx context.Context) string

GetLogID 兼容虚拟机调用项目logid串联问题

func GetLogger

func GetLogger() (s *zap.SugaredLogger)

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

func GetMachineID

func GetMachineID(ctx context.Context) string

func GetRequestID

func GetRequestID(ctx context.Context) string

func GetTenantID

func GetTenantID(ctx context.Context) int64

func GetUserAuthGroup

func GetUserAuthGroup(ctx context.Context) string

func GetUserAuthGroupListByReqCtx

func GetUserAuthGroupListByReqCtx(ctx context.Context) (ctxGroupList []int64)

GetUserAuthGroupListByReqCtx 从请求上下文里获取主机分组权限 优先从请求过来的rpcx上下文中获取- 此种情况为正常的上游rpc请求 上面没有则直接从上下文里获取key - 此种情况一般为mq或定时任务 业务方使用的

func GetUserID

func GetUserID(ctx context.Context) int64

func GetZapLogger

func GetZapLogger() (l *zap.Logger)

func Info

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

func InfoLogger

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

func Infof

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

func InitLog

func InitLog(conf LogConfig) *zap.SugaredLogger

func NewEntry

func NewEntry(s *zap.SugaredLogger) *entry

func NewNNJSONEncoder

func NewNNJSONEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder

func NoLog

func NoLog(ctx context.Context, lvl zapcore.Level) bool

func Panic

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

func PanicLogger

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

func Panicf

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

func RegisterNNJSONEncoder

func RegisterNNJSONEncoder() error

RegisterNNJSONEncoder registers a special jsonEncoder under "zyb-json" name.

func SetNoLogFlag

func SetNoLogFlag(ctx context.Context)

func Warn

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

func WarnLogger

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

func Warnf

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

Types

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"`
	LogRate     bool        `yaml:"logRate"`
	LogRateConf LogRateConf `yaml:"logRateConf"`
}

type LogRateConf

type LogRateConf struct {
	MaxAge     int  `yaml:"maxAge"`
	MaxBackups uint `yaml:"maxBackups"`
	MaxSize    uint `yaml:"maxSize"`
}

LogRateConf log rate config

type XTCPLogger

type XTCPLogger struct {
}

func GetXTCPLogger

func GetXTCPLogger() *XTCPLogger

func (XTCPLogger) Log

func (XTCPLogger) Log(l xtcp.LogLevel, v ...interface{})

func (XTCPLogger) Logf

func (XTCPLogger) Logf(l xtcp.LogLevel, format string, v ...interface{})

Jump to

Keyboard shortcuts

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