logger

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const CallerKey = "caller"

CallerKey is the key for the caller field in logs.

View Source
const LevelKey = "level"

LevelKey is the key for the log level field in logs.

View Source
const MaxAge = 30 * 24 * time.Hour

MaxAge defines the maximum duration to retain log files (30 days).

View Source
const MessageKey = "message"

MessageKey is the key for the message field in logs.

View Source
const NameKey = "name"

NameKey is the key for the logger name field in logs.

View Source
const RotationSize = 500 * 1024 * 1024

RotationSize defines the maximum file size before rotation (500 MB).

View Source
const RotationTime = 24 * time.Hour

RotationTime defines the duration after which log files are rotated (24 hours).

View Source
const StacktraceKey = "stacktrace"

StacktraceKey is the key for the stacktrace field in logs.

View Source
const TimeKey = "time"

TimeKey is the key for the timestamp field in logs.

Variables

This section is empty.

Functions

func Close

func Close()

func EndSpan

func EndSpan(ctx context.Context)

func InitTracer

func InitTracer(name string)

func NewSpan

func NewSpan(ctx context.Context, name string) (context.Context, traceing.Span)

func ShutdownTracer

func ShutdownTracer() error

func SpanID

func SpanID(ctx context.Context) string

func TraceID

func TraceID(ctx context.Context) string

Types

type Config

type Config struct {
	Dir        string        // Dir is the directory for log files.
	TracerName string        // TracerName is the name of the tracer (optional).
	Level      zapcore.Level // Level is the minimum log level to record.
	Encode     EncodeType    // Encode specifies the log encoding format (JSON or console).
	TimeFormat string        // TimeFormat is the format for timestamp fields.
}

Config defines the configuration for initializing a Logger.

type EncodeType

type EncodeType string

EncodeType defines the encoding format for logs.

const (
	ConsoleEncode EncodeType = "console" // ConsoleEncode formats logs in a human-readable console format.
	JSONEncode    EncodeType = "json"    // JSONEncode formats logs in JSON format.
)

Constants for log encoding types.

type Interface

type Interface interface {
	Debug(msg string, fields ...zap.Field)
	Info(msg string, fields ...zap.Field)
	Warn(msg string, fields ...zap.Field)
	Error(msg string, fields ...zap.Field)

	Close() error
	IsDebugEnabled() bool
}

type Logger

type Logger struct {
	*zap.Logger // Embedded zap logger for logging operations.
	// contains filtered or unexported fields
}

Logger wraps a zap logger with file rotation writers.

func Init

func Init(c *Config) (*Logger, error)

Init initializes the singleton Logger with the specified configuration. It creates log files with rotation (by time and size) and supports JSON or console encoding. It returns the initialized Logger and an error if initialization fails (e.g., directory creation or writer setup fails). Subsequent calls return the same instance without reinitializing.

func NameWithOptions added in v0.9.2

func NameWithOptions(name string, option ...zap.Option) *Logger

func Named

func Named(name string) *Logger

Named returns a new Logger with the specified name. It returns nil if the Logger instance is not initialized.

func (*Logger) Close

func (l *Logger) Close() error

Close shuts down the Logger and closes all associated log writers. It returns an error if any writer fails to close.

func (*Logger) IsDebugEnabled

func (l *Logger) IsDebugEnabled() bool

func (*Logger) Named

func (l *Logger) Named(name string) *Logger

Jump to

Keyboard shortcuts

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