slog

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLogFile      = "debug.log"
	OutputLogFile     = "output.log"
	ErrorLogFile      = "error.log"
	DefaultLoggerName = "slog"
)

Variables

View Source
var CDPanic = loggers.CDPanic
View Source
var CDPanicln = loggers.CDPanicln
View Source
var CDPanicw = loggers.CDPanicw
View Source
var CDebug = loggers.CDebug
View Source
var CDebugln = loggers.CDebugln
View Source
var CDebugw = loggers.CDebugw
View Source
var CError = loggers.CError
View Source
var CErrorln = loggers.CErrorln
View Source
var CErrorw = loggers.CErrorw
View Source
var CFatal = loggers.CFatal
View Source
var CFatalln = loggers.CFatalln
View Source
var CFatalw = loggers.CFatalw
View Source
var CInfo = loggers.CInfo
View Source
var CInfoln = loggers.CInfoln
View Source
var CInfow = loggers.CInfow
View Source
var CLog = loggers.CLog
View Source
var CLogln = loggers.CLogln
View Source
var CLogw = loggers.CLogw
View Source
var CPanic = loggers.CPanic
View Source
var CPanicln = loggers.CPanicln
View Source
var CPanicw = loggers.CPanicw
View Source
var CWarn = loggers.CWarn
View Source
var CWarnln = loggers.CWarnln
View Source
var CWarnw = loggers.CWarnw
View Source
var GetLogContext = log_context.GetLogContext
View Source
var NewSLogger = loggers.NewSLogger
View Source
var SetContextKeyValue = log_context.SetLogContextKeyValue
View Source
var ZapLogger *zap.Logger

Functions

func CallerEncoder

func CallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)

func Close

func Close()

func GetConsoleEncoder

func GetConsoleEncoder(hostname string) zapcore.Encoder

func GetContextLogger

func GetContextLogger(ctx context.Context) *zap.SugaredLogger

func GetFileSyncer

func GetFileSyncer(rotateConfig *RotateConfig, dir string, filename string) (zapcore.WriteSyncer, func() (err error))

func GetJsonEncoder

func GetJsonEncoder(hostname string) zapcore.Encoder

func GetRotateConfigs

func GetRotateConfigs(config *LogConfig) (debugConfig *RotateConfig, outputConfig *RotateConfig, errorConfig *RotateConfig)

init rotate config

func Init

func Init(config LogConfig)

func InitEncoders

func InitEncoders() (jsonEncoder zapcore.Encoder, consoleEncoder zapcore.Encoder)

func NameEncoder

func NameEncoder(loggerName string, enc zapcore.PrimitiveArrayEncoder)

Types

type LogConfig

type LogConfig struct {
	Name         string        `mapstructure:"name"`  // logger name, can be service name
	Level        int           `mapstructure:"level"` // zapcore/level.go
	Dir          string        `mapstructure:"dir"`
	Console      bool          `mapstructure:"console"`
	File         bool          `mapstructure:"file"`
	RotateConfig *RotateConfig `mapstructure:"rotate"`
	DebugRotate  *RotateConfig `mapstructure:"debug_rotate"`  // using rotate config, if nil. Debug log will not be collected by log service
	OutputRotate *RotateConfig `mapstructure:"output_rotate"` // using rotate config, if nil
	ErrorRotate  *RotateConfig `mapstructure:"error_rotate"`  // using rotate config, if nil
}

type RotateConfig

type RotateConfig struct {
	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int `mapstructure:"max_size"`
	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int `mapstructure:"max_age"`
	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int `mapstructure:"max_backups"`
	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool `mapstructure:"compress"`
}

type SLogger added in v0.0.8

type SLogger = loggers.SLogger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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