logger

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package logger provides structured logging with different log levels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MinLevel is the minimum log level to output
	MinLevel Level
	// EnableJSON controls whether to output logs in JSON format
	EnableJSON bool
	// Output is where logs are written to
	Output io.Writer
	// IncludeTimestamp controls whether to include a timestamp in logs
	IncludeTimestamp bool
	// IncludeFileLine controls whether to include the file and line number in logs
	IncludeFileLine bool
}

Config holds the logger configuration.

type Fields

type Fields map[string]interface{}

Fields is a type alias for log metadata fields

type Level

type Level int

Level represents the severity level of a log message

const (
	// DebugLevel is the most verbose logging level, used for debugging.
	DebugLevel Level = iota
	// InfoLevel is the standard logging level, used for general information.
	InfoLevel
	// WarnLevel is for logging warnings that don't cause application failure.
	WarnLevel
	// ErrorLevel is for logging errors that affect application function.
	ErrorLevel
	// FatalLevel is for logging fatal errors that require application termination.
	FatalLevel
)

func ParseLevel

func ParseLevel(level string) (Level, error)

ParseLevel parses a string level into a Level.

func (Level) String

func (l Level) String() string

String returns the string representation of the log level.

type Logger

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

Logger is a structured logger that supports different log levels

func DefaultLogger

func DefaultLogger() *Logger

DefaultLogger returns a logger with sensible defaults

func New

func New(config Config) *Logger

New creates a new logger with the provided configuration

func (*Logger) Debug

func (l *Logger) Debug(msg string, metadata ...Fields)

Debug logs a debug message with optional metadata.

func (*Logger) Error

func (l *Logger) Error(msg string, metadata ...Fields)

Error logs an error message with optional metadata.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, metadata ...Fields)

Fatal logs a fatal message with optional metadata and then exits the application.

func (*Logger) GetLevel

func (l *Logger) GetLevel() Level

GetLevel returns the current minimum log level.

func (*Logger) Info

func (l *Logger) Info(msg string, metadata ...Fields)

Info logs an info message with optional metadata.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel sets the minimum log level.

func (*Logger) Warn

func (l *Logger) Warn(msg string, metadata ...Fields)

Warn logs a warning message with optional metadata.

func (*Logger) WithMetadata

func (l *Logger) WithMetadata(_ Fields) *Logger

WithMetadata returns a function that logs with the provided metadata.

Jump to

Keyboard shortcuts

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