Documentation
¶
Overview ¶
* @Author: morehao morehao@qq.com * @Date: 2025-04-26 09:55:22 * @LastEditors: morehao morehao@qq.com * @LastEditTime: 2025-04-26 16:50:59 * @FilePath: /golib/glog/config.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Author: morehao morehao@qq.com * @Date: 2025-04-26 19:13:30 * @LastEditors: morehao morehao@qq.com * @LastEditTime: 2025-04-27 15:20:49 * @FilePath: /golib/glog/logger.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
Index ¶
- Constants
- func Close()
- func Debug(ctx context.Context, args ...any)
- func Debugf(ctx context.Context, format string, kvs ...any)
- func Debugw(ctx context.Context, msg string, kvs ...any)
- func Error(ctx context.Context, args ...any)
- func Errorf(ctx context.Context, format string, kvs ...any)
- func Errorw(ctx context.Context, msg string, kvs ...any)
- func Fatal(ctx context.Context, args ...any)
- func Fatalf(ctx context.Context, format string, kvs ...any)
- func Fatalw(ctx context.Context, msg string, kvs ...any)
- func FormatRequestTime(time time.Time) string
- func GenRequestID() string
- func GetRequestCost(start, end time.Time) float64
- func Info(ctx context.Context, args ...any)
- func Infof(ctx context.Context, format string, kvs ...any)
- func Infow(ctx context.Context, msg string, kvs ...any)
- func InitLogger(cfg *LogConfig, opts ...Option) error
- func Panic(ctx context.Context, args ...any)
- func Panicf(ctx context.Context, format string, kvs ...any)
- func Panicw(ctx context.Context, msg string, kvs ...any)
- func ToJsonString(v any) string
- func Warn(ctx context.Context, args ...any)
- func Warnf(ctx context.Context, format string, kvs ...any)
- func Warnw(ctx context.Context, msg string, kvs ...any)
- type Field
- type FieldHookFunc
- type Level
- type LogConfig
- type Logger
- type LoggerType
- type MessageHookFunc
- type Option
- type RotateIntervalType
- type RotateUnit
- type WriterType
Constants ¶
const ( KeyLogger = "logger" KeyRequestId = "requestId" KeyTraceId = "traceId" KeyTraceFlags = "traceFlags" KeySpanId = "spanId" MsgFlagNotice = "notice" KeySkipLog = "skip" KeyService = "service" KeyHost = "host" KeyClientIp = "clientIp" KeyHandle = "handle" KeyProto = "proto" KeyRefer = "refer" KeyUserAgent = "userAgent" KeyHeader = "header" KeyCookie = "cookie" KeyUri = "uri" KeyMethod = "method" KeyHttpStatusCode = "httpStatusCode" KeyRequestQuery = "requestQuery" KeyRequestBody = "requestBody" KeyRequestBodySize = "requestBodySize" KeyResponseCode = "responseCode" KeyResponseBody = "responseBody" KeyResponseBodySize = "responseBodySize" KeyRequestStartTime = "start" KeyRequestEndTime = "end" KeyCost = "cost" KeyRequestErr = "requestErr" KeyErrorCode = "errorCode" KeyErrorMsg = "errorMsg" KeyAffectedRows = "affectedRows" KeyAddr = "addr" KeyDatabase = "database" KeySql = "sql" KeyCmd = "cmd" KeyCmdContent = "cmdContent" KeyRalCode = "ralCode" KeyFile = "file" KeyDsl = "dsl" KeyDslMethod = "dslMethod" KeyDslPath = "dslPath" ValueProtoHttp = "gresty" ValueProtoMysql = "mysql" ValueProtoRedis = "redis" ValueProtoES = "es" )
Variables ¶
This section is empty.
Functions ¶
func FormatRequestTime ¶
func GetRequestCost ¶
func ToJsonString ¶
Types ¶
type LogConfig ¶
type LogConfig struct { // Service 服务名 Service string // Module 模块名称,如 "es", "gorm", "redis" 等 Module string // Level 日志级别 Level Level `json:"level" yaml:"level"` // Writer 日志输出类型 Writer WriterType `json:"writer" yaml:"writer"` // RotateInterval 日志切割周期,单位为天 RotateInterval RotateIntervalType `json:"rotate_interval" yaml:"rotate_interval"` // Dir 日志文件目录 Dir string `json:"dir" yaml:"dir"` // ExtraKeys 需要从上下文中提取的额外字段 ExtraKeys []string `json:"extra_keys" yaml:"extra_keys"` // RotateUnit 日志切割的时间单位 RotateUnit RotateUnit `json:"rotate_unit" yaml:"rotate_unit"` }
LogConfig 模块级别的日志配置
func GetDefaultLogConfig ¶
func GetDefaultLogConfig() *LogConfig
func GetLoggerConfig ¶
func GetLoggerConfig() *LogConfig
type Logger ¶
type Logger interface { Debug(ctx context.Context, args ...any) Debugf(ctx context.Context, format string, kvs ...any) Debugw(ctx context.Context, msg string, kvs ...any) Info(ctx context.Context, args ...any) Infof(ctx context.Context, format string, kvs ...any) Infow(ctx context.Context, msg string, kvs ...any) Warn(ctx context.Context, args ...any) Warnf(ctx context.Context, format string, kvs ...any) Warnw(ctx context.Context, msg string, kvs ...any) Error(ctx context.Context, args ...any) Errorf(ctx context.Context, format string, kvs ...any) Errorw(ctx context.Context, msg string, kvs ...any) Panic(ctx context.Context, args ...any) Panicf(ctx context.Context, format string, kvs ...any) Panicw(ctx context.Context, msg string, kvs ...any) Fatal(ctx context.Context, args ...any) Fatalf(ctx context.Context, format string, kvs ...any) Fatalw(ctx context.Context, msg string, kvs ...any) Close() // contains filtered or unexported methods }
func GetDefaultLogger ¶
func GetDefaultLogger() Logger
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option 日志选项
func WithMessageHookFunc ¶
func WithMessageHookFunc(fn MessageHookFunc) Option
WithMessageHookFunc 设置消息钩子函数
type RotateIntervalType ¶
type RotateIntervalType string
const ( RotateIntervalTypeHour RotateIntervalType = "hour" RotateIntervalTypeDay RotateIntervalType = "day" )
type RotateUnit ¶
type RotateUnit string
RotateUnit 日志切割的时间单位
const ( RotateUnitDay RotateUnit = "day" RotateUnitHour RotateUnit = "hour" )
type WriterType ¶
type WriterType string
const ( WriterConsole WriterType = "console" WriterFile WriterType = "file" )