log

package
v0.0.0-...-32b1917 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SessionIDKey      = "__xorm_session_id"
	SessionKey        = "__xorm_session_key"
	SessionShowSQLKey = "__xorm_show_sql"
)

Functions

func BuildEncoder

func BuildEncoder(format string) zapcore.Encoder

func Ctx2Fields

func Ctx2Fields(ctx context.Context) []zap.Field

Ctx2Fields *

  • @Description:
  • @param ctx
  • @return []zap.Field

func Debug

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

Debug *

  • @Description:
  • @param msg
  • @param fields

func DebugCtx

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

DebugCtx *

  • @Description:
  • @param ctx
  • @param msg
  • @param fields

func Error

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

Error *

  • @Description:
  • @param msg
  • @param fields

func ErrorCtx

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

ErrorCtx *

  • @Description:
  • @param ctx
  • @param msg
  • @param fields

func Fatal

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

func FatalCtx

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

FatalCtx *

  • @Description:
  • @param ctx
  • @param msg
  • @param fields

func GetLogger

func GetLogger() *zap.Logger

func GetSurgar

func GetSurgar() *zap.SugaredLogger

func GinLogger

func GinLogger() gin.HandlerFunc

GinLogger *

  • @Description:
  • @return gin.HandlerFunc

func GinRecovery

func GinRecovery(stack bool) gin.HandlerFunc

GinRecovery *

  • @Description:
  • @param stack
  • @return gin.HandlerFunc

func Info

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

Info *

  • @Description:
  • @param msg
  • @param fields

func InfoCtx

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

InfoCtx *

  • @Description:
  • @param ctx
  • @param msg
  • @param fields

func Interfaces2String

func Interfaces2String(v ...interface{}) string

func New

func New(cfg *Config)

func NewOrmLoggerAdapter

func NewOrmLoggerAdapter() xlog.ContextLogger

func Panic

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

Panic *

  • @Description:
  • @param msg
  • @param fields

func PanicCtx

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

PanicCtx *

  • @Description:
  • @param ctx
  • @param msg
  • @param fields

func Reset

func Reset(logger *zap.Logger, props *ZapProperties)

func SetLevel

func SetLevel(levelStr string)

SetLevel alters the logging level. *

  • @Description:
  • @param levelStr

func Sync

func Sync() error

func Warn

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

Warn *

  • @Description:
  • @param msg
  • @param fields

func WarnCtx

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

func With

func With(fields ...zap.Field) *zap.Logger

With *

  • @Description: creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.
  • @param fields
  • @return *zap.Logger

Types

type Config

type Config struct {
	CallSkip int           `toml:"callSkip" json:"callSkip"` // Log CallSkip
	Level    string        `toml:"level" json:"level"`       // Log level.
	StdLevel string        `toml:"stdLevel" json:"stdLevel"` // console level
	Format   string        `toml:"format" json:"format"`     // Log format. one of json, text, or console.
	File     FileLogConfig `toml:"file" json:"file"`         // File log config.
}

Config *

  • @Description: serializes log related config in toml/json.

func (*Config) GetLevel

func (c *Config) GetLevel() *Level

GetLevel *

  • @Description:
  • @receiver c
  • @return *Level

func (*Config) GetStdLevel

func (c *Config) GetStdLevel() *Level

GetStdLevel *

  • @Description:
  • @receiver c
  • @return *Level

type ContextLogKey

type ContextLogKey string
const (
	DebugRequestId ContextLogKey = "DebugRequestId" // debug
	RequestIdKey   ContextLogKey = "rid"
	SessionId      ContextLogKey = "sessionId"
	TraceId        ContextLogKey = "traceId"
	SpanId         ContextLogKey = "spanId"
	ThreadId       ContextLogKey = "threadId"
	Cluster        ContextLogKey = "cluster"
	AppName        ContextLogKey = "appName"
	ServerAddr     ContextLogKey = "serverAddr"
	ServerPort     ContextLogKey = "serverPort"
	Version        ContextLogKey = "version"

	Category ContextLogKey = "logCategory"

	HttpPath     ContextLogKey = "httpPath"   //nolint:gosec
	HttpMethod   ContextLogKey = "httpMethod" //nolint:gosec
	QueryText    ContextLogKey = "query"
	ContentType  ContextLogKey = "contentType"
	StatusCode   ContextLogKey = "statusCode"
	RequestSize  ContextLogKey = "requestSize"
	HttpRequest  ContextLogKey = "httpRequest"
	HttpResponse ContextLogKey = "httpResponse"
	ClientIp     ContextLogKey = "clientIp"
	UserAgent    ContextLogKey = "userAgent"
	Errors       ContextLogKey = "errors"

	Message ContextLogKey = "msg"

	BusinessKeyword   ContextLogKey = "businessKeyword"
	BusinessTitle     ContextLogKey = "businessTitle"
	BusinessOperation ContextLogKey = "businessOperation"
	BusinessUserID    ContextLogKey = "businessUserID"

	Datetime ContextLogKey = "datetime"
	Caller   ContextLogKey = "caller"

	Duration ContextLogKey = "duration"
	LevelKey ContextLogKey = "level"
)

func (ContextLogKey) ToString

func (key ContextLogKey) ToString() string

type FileLogConfig

type FileLogConfig struct {
	FileDir    string `toml:"fileDir" json:"fileDir"`
	FileName   string `toml:"fileName" json:"fileName"`     // Log filename, leave empty to disable file log.
	MaxSize    int    `toml:"maxSize" json:"maxSize"`       // Max size for a single file, in MB.
	MaxDays    int    `toml:"maxDays" json:"maxDays"`       // Max log keep days, default is never deleting.
	MaxBackups int    `toml:"maxBackups" json:"maxBackups"` // Maximum number of old log files to retain.
	Compress   bool   `toml:"compress" json:"compress"`     // Compress
}

FileLogConfig *

  • @Description: serializes file log related config in toml/json.

type Level

type Level int8

Level is a logging priority. Higher levels are more important.

const (
	DebugLevel Level = iota - 1
	InfoLevel
	WarnLevel
	ErrorLevel
	CriticalLevel // Critical exists only for config backward compatibility.
)

Logging levels.

func GetLevel

func GetLevel() *Level

GetLevel *

  • @Description:
  • @return *Level

func (Level) String

func (l Level) String() string

String returns the name of the logging level.

func (Level) Unabled

func (l Level) Unabled(level Level) bool

Unabled returns true if given level is enabled.

func (*Level) Unpack

func (l *Level) Unpack(str string) error

Unpack unmarshals a level string to a Level. This implements ucfg.StringUnpacker.

type LoggerCtxFunc

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

type LoggerFunc

type LoggerFunc func(msg string, fields ...zap.Field)

type OrmCtxLogger

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

func (*OrmCtxLogger) AfterSQL

func (l *OrmCtxLogger) AfterSQL(context xlog.LogContext)

func (*OrmCtxLogger) BeforeSQL

func (l *OrmCtxLogger) BeforeSQL(context xlog.LogContext)

func (*OrmCtxLogger) Debugf

func (l *OrmCtxLogger) Debugf(format string, v ...interface{})

func (*OrmCtxLogger) Errorf

func (l *OrmCtxLogger) Errorf(format string, v ...interface{})

func (*OrmCtxLogger) Infof

func (l *OrmCtxLogger) Infof(format string, v ...interface{})

func (*OrmCtxLogger) IsShowSQL

func (l *OrmCtxLogger) IsShowSQL() bool

func (*OrmCtxLogger) Level

func (l *OrmCtxLogger) Level() xlog.LogLevel

func (*OrmCtxLogger) SetLevel

func (l *OrmCtxLogger) SetLevel(level xlog.LogLevel)

func (*OrmCtxLogger) ShowSQL

func (l *OrmCtxLogger) ShowSQL(show ...bool)

func (*OrmCtxLogger) Warnf

func (l *OrmCtxLogger) Warnf(format string, v ...interface{})

type OrmLogger

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

func (*OrmLogger) Debug

func (l *OrmLogger) Debug(v ...interface{})

func (*OrmLogger) Debugf

func (l *OrmLogger) Debugf(format string, v ...interface{})

func (*OrmLogger) Error

func (l *OrmLogger) Error(v ...interface{})

func (*OrmLogger) Errorf

func (l *OrmLogger) Errorf(format string, v ...interface{})

func (*OrmLogger) Info

func (l *OrmLogger) Info(v ...interface{})

func (*OrmLogger) Infof

func (l *OrmLogger) Infof(format string, v ...interface{})

func (*OrmLogger) IsShowSQL

func (l *OrmLogger) IsShowSQL() bool

func (*OrmLogger) Level

func (l *OrmLogger) Level() xlog.LogLevel

func (*OrmLogger) SetLevel

func (l *OrmLogger) SetLevel(level xlog.LogLevel)

func (*OrmLogger) ShowSQL

func (l *OrmLogger) ShowSQL(show ...bool)

func (*OrmLogger) Warn

func (l *OrmLogger) Warn(v ...interface{})

func (*OrmLogger) Warnf

func (l *OrmLogger) Warnf(format string, v ...interface{})

type OrmLoggerAdapter

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

func (*OrmLoggerAdapter) AfterSQL

func (l *OrmLoggerAdapter) AfterSQL(ctx xlog.LogContext)

AfterSQL implements ContextLogger

func (*OrmLoggerAdapter) BeforeSQL

func (l *OrmLoggerAdapter) BeforeSQL(ctx xlog.LogContext)

BeforeSQL implements ContextLogger

func (*OrmLoggerAdapter) Debugf

func (l *OrmLoggerAdapter) Debugf(format string, v ...interface{})

Debugf implements ContextLogger

func (*OrmLoggerAdapter) Errorf

func (l *OrmLoggerAdapter) Errorf(format string, v ...interface{})

Errorf implements ContextLogger

func (*OrmLoggerAdapter) Infof

func (l *OrmLoggerAdapter) Infof(format string, v ...interface{})

Infof implements ContextLogger

func (*OrmLoggerAdapter) IsShowSQL

func (l *OrmLoggerAdapter) IsShowSQL() bool

IsShowSQL implements ContextLogger

func (*OrmLoggerAdapter) Level

func (l *OrmLoggerAdapter) Level() xlog.LogLevel

Level implements ContextLogger

func (*OrmLoggerAdapter) SetLevel

func (l *OrmLoggerAdapter) SetLevel(lv xlog.LogLevel)

SetLevel implements ContextLogger

func (*OrmLoggerAdapter) ShowSQL

func (l *OrmLoggerAdapter) ShowSQL(show ...bool)

ShowSQL implements ContextLogger

func (*OrmLoggerAdapter) Warnf

func (l *OrmLoggerAdapter) Warnf(format string, v ...interface{})

Warnf implements ContextLogger

type ZapProperties

type ZapProperties struct {
	Core   zapcore.Core
	Syncer zapcore.WriteSyncer
	Level  *Level
}

func InitLogger

func InitLogger(cfg *Config, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)

InitLogger initializes a zap logger.

func InitLoggerWithWriteSyncer

func InitLoggerWithWriteSyncer(cfg *Config, output zapcore.WriteSyncer, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)

InitLoggerWithWriteSyncer initializes a zap logger with specified write syncer.

Jump to

Keyboard shortcuts

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