log

package module
v0.0.0-...-9eb51ae Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestLogger

func RequestLogger(logger *Logger) func(next http.Handler) http.Handler

RequestLogger is a middleware that logs HTTP requests

Types

type ConsoleDestination

type ConsoleDestination struct{}

ConsoleDestination writes logs to the console

func (*ConsoleDestination) Close

func (c *ConsoleDestination) Close() error

Close closes the console destination (no-op for console)

func (*ConsoleDestination) Write

func (c *ConsoleDestination) Write(p []byte) (n int, err error)

Write writes log entry to console (stdout)

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field represents a key-value pair for structured logging

func NewField

func NewField(key string, value interface{}) Field

type FileDestination

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

FileDestination writes logs to a file

func NewFileDestination

func NewFileDestination(filePath string) (*FileDestination, error)

NewFileDestination initializes a new file destination for logs

func (*FileDestination) Close

func (f *FileDestination) Close() error

Close closes the file

func (*FileDestination) Write

func (f *FileDestination) Write(p []byte) (n int, err error)

Write writes log entry to a file

type Level

type Level int

Level represents the severity of the log message.

const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
	FATAL
)

type Logger

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

func NewLogger

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

func NewSilentLogger

func NewSilentLogger() (*Logger, error)

NewSilentLogger creates a logger that silences all log output

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...Field)

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...Field)

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...Field)

func (*Logger) Flush

func (l *Logger) Flush() error

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...Field)

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...Field)

type LoggerConfig

type LoggerConfig struct {
	Level       Level
	Destination io.WriteCloser
	ServiceName string
}

type RemoteDestination

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

RemoteDestination simulates sending logs to a remote aggregator (e.g., Prometheus or Grafana)

func NewRemoteDestination

func NewRemoteDestination(url string) *RemoteDestination

func (*RemoteDestination) Close

func (r *RemoteDestination) Close() error

Close closes the remote destination (no-op for this example)

func (*RemoteDestination) Write

func (r *RemoteDestination) Write(p []byte) (n int, err error)

Write sends log entry to remote destination

Jump to

Keyboard shortcuts

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