logging

package
v10.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

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 Context

func Context(ctx context.Context) *zap.Logger

func FromLogger

func FromLogger(ctx context.Context) *zap.Logger

func FromStack

func FromStack(ctx context.Context) string

func FromTag

func FromTag(ctx context.Context) string

func FromTraceID

func FromTraceID(ctx context.Context) string

func FromUserID

func FromUserID(ctx context.Context) string

func InitWithConfig

func InitWithConfig(ctx context.Context, cfg *LoggerConfig, hookHandle ...HookHandlerFunc) (func(), error)

func NewLogger

func NewLogger(ctx context.Context, logger *zap.Logger) context.Context

func NewStack

func NewStack(ctx context.Context, stack string) context.Context

func NewTag

func NewTag(ctx context.Context, tag string) context.Context

func NewTraceID

func NewTraceID(ctx context.Context, traceID string) context.Context

func NewUserID

func NewUserID(ctx context.Context, userID string) context.Context

Types

type Config

type Config struct {
	Logger LoggerConfig
}

type GormHook

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

Gorm Logger Hook

func NewGormHook

func NewGormHook(db *gorm.DB) *GormHook

func (*GormHook) Close

func (h *GormHook) Close() error

func (*GormHook) Exec

func (h *GormHook) Exec(extra map[string]string, b []byte) error

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

func (*Hook) Flush

func (h *Hook) Flush()

Waits for the log queue to be empty

func (*Hook) Write

func (h *Hook) Write(p []byte) (int, error)

type HookConfig

type HookConfig struct {
	Enable    bool
	Level     string
	Type      string // gorm
	MaxBuffer int
	MaxThread int
	Options   map[string]string
	Extra     map[string]string
}

type HookExecuter

type HookExecuter interface {
	Exec(extra map[string]string, b []byte) error
	Close() error
}

type HookHandlerFunc

type HookHandlerFunc func(ctx context.Context, hookCfg *HookConfig) (*Hook, error)

type HookOption

type HookOption func(*hookOptions)

HookOption a hook parameter options

func SetHookExtra

func SetHookExtra(extra map[string]string) HookOption

Set extended parameters

func SetHookMaxJobs

func SetHookMaxJobs(maxJobs int) HookOption

Set the number of buffers

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{})

Jump to

Keyboard shortcuts

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