logging

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package logging provides a unified logging interface using zap

Package logging provides a unified logging interface using zap

Package logging provides a unified logging interface

Index

Constants

View Source
const (
	// LogEncodingConsole represents console encoding for logs
	LogEncodingConsole = "console"
	// LogEncodingJSON represents JSON encoding for logs
	LogEncodingJSON = "json"
)

Variables

This section is empty.

Functions

func FromAppConfig

func FromAppConfig(appName, logLevel string, debug bool) *config.Config

FromAppConfig converts an application config to a logging config

Types

type Config

type Config struct {
	Level   string
	AppName string
}

Config holds the configuration for creating a logger

type Factory

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

Factory creates loggers based on configuration

func NewFactory

func NewFactory() *Factory

NewFactory creates a new logger factory

func (*Factory) AuthLogger

func (f *Factory) AuthLogger(logger Logger) Logger

AuthLogger returns the shared logger for auth middleware

func (*Factory) CookieAuthLogger

func (f *Factory) CookieAuthLogger(logger Logger) Logger

CookieAuthLogger returns the shared logger for cookie auth middleware

func (*Factory) CreateFromConfig

func (f *Factory) CreateFromConfig(cfg *config.Config) (Logger, error)

CreateFromConfig creates a logger based on the provided configuration

func (*Factory) CreateLogger

func (f *Factory) CreateLogger() (Logger, error)

CreateLogger creates a logger with default configuration

func (*Factory) CreateTestLogger

func (f *Factory) CreateTestLogger() (Logger, error)

CreateTestLogger creates a logger for testing

type FxEventLogger

type FxEventLogger struct {
	Logger Logger
}

FxEventLogger implements fxevent.Logger interface using our Logger

func (*FxEventLogger) LogEvent

func (l *FxEventLogger) LogEvent(event fxevent.Event)

LogEvent logs fx lifecycle events

type LogField

type LogField struct {
	Key   string
	Value any
}

LogField represents a field in a log entry

func Any

func Any(key string, value any) LogField

Any creates a field for any type

func AnyField

func AnyField(key string, value any) LogField

AnyField creates a field for any type

func Bool

func Bool(key string, value bool) LogField

Bool creates a boolean field

func BoolField

func BoolField(key string, value bool) LogField

BoolField creates a boolean field

func Duration

func Duration(key string, value time.Duration) LogField

Duration creates a duration field

func DurationField

func DurationField(key string, value time.Duration) LogField

DurationField creates a duration field

func Error

func Error(err error) LogField

Error creates an error field

func ErrorField

func ErrorField(key string, err error) LogField

ErrorField creates an error field

func Int

func Int(key string, value int) LogField

Int creates an integer field

func Int64

func Int64(key string, value int64) LogField

Int64 creates a 64-bit integer field

func IntField

func IntField(key string, value int) LogField

IntField creates an integer field

func String

func String(key, value string) LogField

String creates a string field

func StringField

func StringField(key, value string) LogField

StringField creates a string field

func Uint

func Uint(key string, value uint) LogField

Uint creates an unsigned integer field

func UintField

func UintField(key string, value uint) LogField

UintField creates an unsigned integer field

type Logger

type Logger interface {
	common.Logger
	Fatal(msg string, fields ...any)
	With(fields ...any) Logger
}

Logger extends the common.Logger interface with additional functionality

func NewLogger

func NewLogger(logLevel, appName string) (Logger, error)

func NewNoopLogger

func NewNoopLogger() Logger

func NewTestLogger

func NewTestLogger() (Logger, error)

func NewZapLogger

func NewZapLogger(zapLog *zap.Logger) Logger

type ZapLogger

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

ZapLogger implements the Logger interface using zap

func (*ZapLogger) Debug

func (l *ZapLogger) Debug(msg string, fields ...any)

Debug logs a debug message

func (*ZapLogger) Error

func (l *ZapLogger) Error(msg string, fields ...any)

Error logs an error message

func (*ZapLogger) Fatal

func (l *ZapLogger) Fatal(msg string, fields ...any)

Fatal logs a fatal message

func (*ZapLogger) GetZapLogger

func (l *ZapLogger) GetZapLogger() *zap.Logger

GetZapLogger returns the underlying zap logger

func (*ZapLogger) Info

func (l *ZapLogger) Info(msg string, fields ...any)

Info logs an info message

func (*ZapLogger) Warn

func (l *ZapLogger) Warn(msg string, fields ...any)

Warn logs a warning message

func (*ZapLogger) With

func (l *ZapLogger) With(fields ...any) Logger

With returns a new logger with the given fields

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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