clog

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug logs a debug message using the global logger

func Debugf

func Debugf(msg string, fields ...Field)

Debugf logs a debug message without context

func Enabled

func Enabled(level Level) bool

Enabled checks if the given level is enabled

func Error

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

Error logs an error message using the global logger

func Errorf

func Errorf(msg string, fields ...Field)

Errorf logs an error message without context

func Fatal

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

Fatal logs a fatal message and exits using the global logger

func Info

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

Info logs an info message using the global logger

func Infof

func Infof(msg string, fields ...Field)

Infof logs an info message without context

func InitGlobalLogger

func InitGlobalLogger(config *Config) error

InitGlobalLogger initializes the global logger instance

func SetGlobalLogger

func SetGlobalLogger(logger Logger)

SetGlobalLogger sets the global logger instance directly

func Sync

func Sync() error

Sync flushes any buffered log entries

func ToZapFields

func ToZapFields(fields []Field) []zap.Field

Convert multiple fields to zap fields

func Warn

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

Warn logs a warning message using the global logger

func Warnf

func Warnf(msg string, fields ...Field)

Warnf logs a warning message without context

Types

type Config

type Config struct {
	Level         string          `yaml:"level" json:"level"`
	Format        string          `yaml:"format" json:"format"` // json, console
	DisableCaller bool            `yaml:"disable_caller" json:"disable_caller"`
	OutputPaths   []string        `yaml:"output_paths" json:"output_paths"`
	Rotation      *RotationConfig `yaml:"rotation" json:"rotation"`
}

Config holds the configuration for logger

func ConfigFromSettings

func ConfigFromSettings(logLevel string) *Config

ConfigFromSettings creates config from AIM settings

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default logger configuration

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field represents a key-value pair for structured logging

func Any

func Any(key string, val interface{}) Field

func Bool

func Bool(key string, val bool) Field

func Duration

func Duration(key string, val time.Duration) Field

func Err

func Err(err error) Field

func Int

func Int(key string, val int) Field

func Int64

func Int64(key string, val int64) Field

func String

func String(key, val string) Field

Helper functions for creating fields

func Time

func Time(key string, val time.Time) Field

func (Field) ToZapField

func (f Field) ToZapField() zap.Field

Convert our Field to zap.Field

type Level

type Level int8

Level represents the logging level

const (
	DebugLevel Level = iota - 1
	InfoLevel
	WarnLevel
	ErrorLevel
	DPanicLevel
	PanicLevel
	FatalLevel
)

func ParseLevel

func ParseLevel(s string) Level

ParseLevel parses a level string

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Debug(ctx context.Context, msg string, fields ...Field)
	Info(ctx context.Context, msg string, fields ...Field)
	Warn(ctx context.Context, msg string, fields ...Field)
	Error(ctx context.Context, msg string, fields ...Field)
	DPanic(ctx context.Context, msg string, fields ...Field)
	Panic(ctx context.Context, msg string, fields ...Field)
	Fatal(ctx context.Context, msg string, fields ...Field)

	// Convenience methods without context
	Debugf(msg string, fields ...Field)
	Infof(msg string, fields ...Field)
	Warnf(msg string, fields ...Field)
	Errorf(msg string, fields ...Field)

	Enabled(level Level) bool

	WithFields(fields map[string]interface{}) Logger
	WithField(key string, value interface{}) Logger
	WithError(err error) Logger

	Sync() error
}

Logger defines the core logging interface

func GetGlobalLogger

func GetGlobalLogger() Logger

GetGlobalLogger returns the global logger instance

func NewLogger

func NewLogger(config *Config) (Logger, error)

NewLogger creates a new zap-based logger

func NewLoggerWithCallerSkip

func NewLoggerWithCallerSkip(config *Config, callerSkip int) (Logger, error)

NewLoggerWithCallerSkip creates a new zap-based logger with caller skip

func WithError

func WithError(err error) Logger

WithError returns a logger with an error field

func WithField

func WithField(key string, value interface{}) Logger

WithField returns a logger with an additional field

func WithFields

func WithFields(fields map[string]interface{}) Logger

WithFields returns a logger with additional fields

type NoOpLogger

type NoOpLogger struct{}

NoOpLogger implements Logger interface with no-op operations

func (*NoOpLogger) DPanic

func (l *NoOpLogger) DPanic(ctx context.Context, msg string, fields ...Field)

func (*NoOpLogger) Debug

func (l *NoOpLogger) Debug(ctx context.Context, msg string, fields ...Field)

func (*NoOpLogger) Debugf

func (l *NoOpLogger) Debugf(msg string, fields ...Field)

func (*NoOpLogger) Enabled

func (l *NoOpLogger) Enabled(level Level) bool

func (*NoOpLogger) Error

func (l *NoOpLogger) Error(ctx context.Context, msg string, fields ...Field)

func (*NoOpLogger) Errorf

func (l *NoOpLogger) Errorf(msg string, fields ...Field)

func (*NoOpLogger) Fatal

func (l *NoOpLogger) Fatal(ctx context.Context, msg string, fields ...Field)

func (*NoOpLogger) Info

func (l *NoOpLogger) Info(ctx context.Context, msg string, fields ...Field)

func (*NoOpLogger) Infof

func (l *NoOpLogger) Infof(msg string, fields ...Field)

func (*NoOpLogger) Panic

func (l *NoOpLogger) Panic(ctx context.Context, msg string, fields ...Field)

func (*NoOpLogger) Sync

func (l *NoOpLogger) Sync() error

func (*NoOpLogger) Warn

func (l *NoOpLogger) Warn(ctx context.Context, msg string, fields ...Field)

func (*NoOpLogger) Warnf

func (l *NoOpLogger) Warnf(msg string, fields ...Field)

func (*NoOpLogger) WithError

func (l *NoOpLogger) WithError(err error) Logger

func (*NoOpLogger) WithField

func (l *NoOpLogger) WithField(key string, value interface{}) Logger

func (*NoOpLogger) WithFields

func (l *NoOpLogger) WithFields(fields map[string]interface{}) Logger

type RotationConfig

type RotationConfig struct {
	MaxSize    int  `yaml:"max_size" json:"max_size"`       // MB
	MaxBackups int  `yaml:"max_backups" json:"max_backups"` // number of backups
	MaxAge     int  `yaml:"max_age" json:"max_age"`         // days
	Compress   bool `yaml:"compress" json:"compress"`
}

RotationConfig holds log rotation settings

type ZapLoggerImpl

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

ZapLoggerImpl implements Logger interface using zap

func (*ZapLoggerImpl) DPanic

func (l *ZapLoggerImpl) DPanic(ctx context.Context, msg string, fields ...Field)

func (*ZapLoggerImpl) Debug

func (l *ZapLoggerImpl) Debug(ctx context.Context, msg string, fields ...Field)

Logger implementation methods

func (*ZapLoggerImpl) Debugf

func (l *ZapLoggerImpl) Debugf(msg string, fields ...Field)

Convenience methods without context

func (*ZapLoggerImpl) Enabled

func (l *ZapLoggerImpl) Enabled(level Level) bool

func (*ZapLoggerImpl) Error

func (l *ZapLoggerImpl) Error(ctx context.Context, msg string, fields ...Field)

func (*ZapLoggerImpl) Errorf

func (l *ZapLoggerImpl) Errorf(msg string, fields ...Field)

func (*ZapLoggerImpl) Fatal

func (l *ZapLoggerImpl) Fatal(ctx context.Context, msg string, fields ...Field)

func (*ZapLoggerImpl) Info

func (l *ZapLoggerImpl) Info(ctx context.Context, msg string, fields ...Field)

func (*ZapLoggerImpl) Infof

func (l *ZapLoggerImpl) Infof(msg string, fields ...Field)

func (*ZapLoggerImpl) Panic

func (l *ZapLoggerImpl) Panic(ctx context.Context, msg string, fields ...Field)

func (*ZapLoggerImpl) Sync

func (l *ZapLoggerImpl) Sync() error

func (*ZapLoggerImpl) Warn

func (l *ZapLoggerImpl) Warn(ctx context.Context, msg string, fields ...Field)

func (*ZapLoggerImpl) Warnf

func (l *ZapLoggerImpl) Warnf(msg string, fields ...Field)

func (*ZapLoggerImpl) WithError

func (l *ZapLoggerImpl) WithError(err error) Logger

func (*ZapLoggerImpl) WithField

func (l *ZapLoggerImpl) WithField(key string, value interface{}) Logger

func (*ZapLoggerImpl) WithFields

func (l *ZapLoggerImpl) WithFields(fields map[string]interface{}) Logger

Jump to

Keyboard shortcuts

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