Documentation ¶
Index ¶
- Constants
- func Context(ctx context.Context) *zap.Logger
- func FromLogger(ctx context.Context) *zap.Logger
- func FromStack(ctx context.Context) string
- func FromTag(ctx context.Context) string
- func FromTraceID(ctx context.Context) string
- func FromUserID(ctx context.Context) string
- func InitWithConfig(ctx context.Context, cfg *LoggerConfig, hookHandle ...HookHandlerFunc) (func(), error)
- func NewLogger(ctx context.Context, logger *zap.Logger) context.Context
- func NewStack(ctx context.Context, stack string) context.Context
- func NewTag(ctx context.Context, tag string) context.Context
- func NewTraceID(ctx context.Context, traceID string) context.Context
- func NewUserID(ctx context.Context, userID string) context.Context
- type Config
- type GormHook
- type Hook
- type HookConfig
- type HookExecuter
- type HookHandlerFunc
- type HookOption
- type Logger
- type LoggerConfig
- type PrintLogger
Constants ¶
View Source
const ( TagKeyMain = "main" TagKeyRecovery = "recovery" TagKeyRequest = "request" TagKeyLogin = "login" TagKeyLogout = "logout" TagKeySystem = "system" TagKeyOperate = "operate" )
Variables ¶
This section is empty.
Functions ¶
func FromTraceID ¶
func FromUserID ¶
func InitWithConfig ¶
func InitWithConfig(ctx context.Context, cfg *LoggerConfig, hookHandle ...HookHandlerFunc) (func(), error)
Types ¶
type Config ¶
type Config struct {
Logger LoggerConfig
}
type GormHook ¶
type GormHook struct {
// contains filtered or unexported fields
}
Gorm Logger Hook
func NewGormHook ¶
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook to send logs to a mongo database
func NewHook ¶
func NewHook(exec HookExecuter, opt ...HookOption) *Hook
Creates a hook to be added to an instance of logger
type HookConfig ¶
type HookExecuter ¶
type HookHandlerFunc ¶
type HookHandlerFunc func(ctx context.Context, hookCfg *HookConfig) (*Hook, error)
type HookOption ¶
type HookOption func(*hookOptions)
HookOption a hook parameter options
func SetHookMaxWorkers ¶
func SetHookMaxWorkers(maxWorkers int) HookOption
Set the number of worker threads
type Logger ¶
type Logger struct { ID string `gorm:"size:20;primaryKey;" json:"id"` // Unique ID Level string `gorm:"size:20;index;" json:"level"` // Log level TraceID string `gorm:"size:64;index;" json:"trace_id"` // Trace ID UserID string `gorm:"size:20;index;" json:"user_id"` // User ID Tag string `gorm:"size:32;index;" json:"tag"` // Log tag Message string `gorm:"size:1024;" json:"message"` // Log message Stack string `gorm:"type:text;" json:"stack"` // Error stack Data string `gorm:"type:text;" json:"data"` // Log data CreatedAt time.Time `gorm:"index;" json:"created_at"` // Create time }
type LoggerConfig ¶
type LoggerConfig struct { Debug bool Level string // debug/info/warn/error/dpanic/panic/fatal CallerSkip int File struct { Enable bool Path string MaxSize int MaxBackups int } Hooks []*HookConfig }
func LoadConfigFromToml ¶
func LoadConfigFromToml(filename string) (*LoggerConfig, error)
type PrintLogger ¶
type PrintLogger struct{}
func (*PrintLogger) Printf ¶
func (a *PrintLogger) Printf(format string, args ...interface{})
Click to show internal directories.
Click to hide internal directories.