logging

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLogger

func DefaultLogger() *zap.Logger

DefaultLogger returns the singleton logger instance

func ErrField

func ErrField(err error) zap.Field

ErrField is a helper to create an error field for logging

func FromContext

func FromContext(ctx context.Context) *zap.Logger

FromContext retrieves a logger from context, or returns default

func NewLogger

func NewLogger(cfg *Config) *zap.Logger

NewLogger creates a new logger with dual output (console + file)

func SetConfig

func SetConfig(c *Config)

SetConfig updates the global logging configuration

func SetLevel

func SetLevel(l zapcore.Level)

SetLevel updates just the log level

func Type

func Type(name string) *zap.Logger

Type returns a logger with a type field for identification

func TypeField

func TypeField(value string) zap.Field

TypeField is a helper to create a type field for logging

func WithContext

func WithContext(ctx context.Context, logger *zap.Logger) context.Context

WithContext stores a logger in the context

Types

type Config

type Config struct {
	Level      zapcore.Level
	FilePath   string
	TimeFormat string // e.g., "2006-01-02 15:04:05" or "02/01/2006 03:04 PM"
}

Config holds logging configuration

type GormLogger

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

GormLogger wraps zap.Logger to implement gorm's logger interface

func NewGormLogger

func NewGormLogger() *GormLogger

NewGormLogger creates a new GORM logger using zap

func (*GormLogger) Error

func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})

Error logs error messages

func (*GormLogger) Info

func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})

Info logs info messages

func (*GormLogger) LogMode

LogMode sets the log level

func (*GormLogger) Trace

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

Trace logs SQL queries

func (*GormLogger) Warn

func (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

Warn logs warn messages

Jump to

Keyboard shortcuts

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