Documentation
¶
Index ¶
- Constants
- Variables
- func FieldMap(fields []Field) map[string]any
- func FieldsToZap(fields []Field) []zap.Field
- func NewTestLogger() log.Logger
- func SetGlobalLogger(logger Logger)
- func ValidateField(field Field) error
- type BeautifulColorScheme
- type BeautifulLogger
- type CustomField
- type ErrorHandler
- type Field
- type FieldGroup
- type FormatConfig
- type LazyField
- type LogEntry
- type LogLevel
- type Logger
- type LoggingConfig
- type LoggingWriter
- type PerformanceMonitor
- type StructuredLog
- type SugarLogger
- type TestLogger
- type ZapField
Constants ¶
const ( LevelInfo = log.LevelInfo LevelWarn = log.LevelWarn LevelError = log.LevelError LevelFatal = log.LevelFatal LevelDebug = log.LevelDebug )
Variables ¶
var ( LoggerFromContext = log.LoggerFromContext WithRequestID = log.WithRequestID RequestIDFromContext = log.RequestIDFromContext WithTraceID = log.WithTraceID TraceIDFromContext = log.TraceIDFromContext WithUserID = log.WithUserID UserIDFromContext = log.UserIDFromContext )
var ( Track = log.Track TrackWithLogger = log.TrackWithLogger TrackWithFields = log.TrackWithFields LogPanic = log.LogPanic LogPanicWithFields = log.LogPanicWithFields )
Re-export utility functions.
var ( // String creates a string field. String = log.String // Int creates an int field. Int = log.Int // Int8 creates an int8 field. Int8 = log.Int8 // Int16 creates an int16 field. Int16 = log.Int16 // Int32 creates an int32 field. Int32 = log.Int32 // Int64 creates an int64 field. Int64 = log.Int64 // Uint creates a uint field. Uint = log.Uint // Uint8 creates a uint8 field. Uint8 = log.Uint8 // Uint16 creates a uint16 field. Uint16 = log.Uint16 // Uint32 creates a uint32 field. Uint32 = log.Uint32 // Uint64 creates a uint64 field. Uint64 = log.Uint64 // Float32 creates a float32 field. Float32 = log.Float32 // Float64 creates a float64 field. Float64 = log.Float64 // Bool creates a bool field. Bool = log.Bool // Time creates a time field. Time = log.Time // Duration creates a duration field. Duration = log.Duration // Error creates an error field. Error = log.Error // Stringer creates a field from a Stringer. Stringer = log.Stringer Any = log.Any Namespace = log.Namespace Binary = log.Binary ByteString = log.ByteString Reflect = log.Reflect Complex64 = log.Complex64 Complex128 = log.Complex128 Object = log.Object Array = log.Array Stack = log.Stack Strings = log.Strings )
Field constructors that return wrapped fields.
var ( // HTTPMethod creates an HTTP method field. HTTPMethod = log.HTTPMethod // HTTPStatus creates an HTTP status field. HTTPStatus = log.HTTPStatus // HTTPPath creates an HTTP path field. HTTPPath = log.HTTPPath // HTTPURL creates an HTTP URL field. HTTPURL = log.HTTPURL // HTTPUserAgent creates an HTTP user agent field. HTTPUserAgent = log.HTTPUserAgent // DatabaseQuery creates a database query field. DatabaseQuery = log.DatabaseQuery // DatabaseTable creates a database table field. DatabaseTable = log.DatabaseTable // DatabaseRows creates a database rows affected field. DatabaseRows = log.DatabaseRows // ServiceName creates a service name field. ServiceName = log.ServiceName // ServiceVersion creates a service version field. ServiceVersion = log.ServiceVersion // ServiceEnvironment creates a service environment field. ServiceEnvironment = log.ServiceEnvironment // LatencyMs creates a latency milliseconds field. LatencyMs = log.LatencyMs MemoryUsage = log.MemoryUsage // Custom field constructors. Custom = log.Custom Lazy = log.Lazy // Conditional field - only adds field if condition is true. Conditional = log.Conditional // Nullable field - only adds field if value is not nil. Nullable = log.Nullable )
Utility field constructors.
var ( // RequestID creates a request ID field. RequestID = log.RequestID // TraceID creates a trace ID field. TraceID = log.TraceID // UserID creates a user ID field. UserID = log.UserID // ContextFields creates fields from context. ContextFields = log.ContextFields )
Context-aware field constructors.
var ( // HTTPRequestGroup creates a group of HTTP request fields. HTTPRequestGroup = func(method, path, userAgent string, status int) *FieldGroup { return log.HTTPRequestGroup( method, path, userAgent, status, ) } // DatabaseQueryGroup creates a group of database query fields. DatabaseQueryGroup = func(query, table string, rows int64, duration time.Duration) *FieldGroup { return log.DatabaseQueryGroup( query, table, rows, duration, ) } // ServiceInfoGroup creates a group of service information fields. ServiceInfoGroup = func(name, version, environment string) *FieldGroup { return log.ServiceInfoGroup( name, version, environment, ) } )
Predefined field groups.
Functions ¶
func FieldsToZap ¶
FieldsToZap converts Field interfaces to zap.Field efficiently.
func NewTestLogger ¶
func SetGlobalLogger ¶
func SetGlobalLogger(logger Logger)
func ValidateField ¶
ValidateField validates a field and returns an error if invalid.
Types ¶
type BeautifulColorScheme ¶ added in v0.3.0
type BeautifulColorScheme = log.BeautifulColorScheme
BeautifulColorScheme defines the color palette for beautiful output.
func DefaultBeautifulColorScheme ¶ added in v0.3.0
func DefaultBeautifulColorScheme() BeautifulColorScheme
DefaultBeautifulColorScheme provides a modern minimalist color scheme.
type BeautifulLogger ¶ added in v0.3.0
type BeautifulLogger = log.BeautifulLogger
BeautifulLogger is a visually appealing alternative logger implementation with CLI-style output, caller information, and configurable formatting.
func NewBeautifulLogger ¶ added in v0.3.0
func NewBeautifulLogger(name string) *BeautifulLogger
NewBeautifulLogger creates a new beautiful logger with defaults.
func NewBeautifulLoggerCompact ¶ added in v0.3.0
func NewBeautifulLoggerCompact(name string) *BeautifulLogger
NewBeautifulLoggerCompact creates a compact logger optimized for high-frequency logs.
func NewBeautifulLoggerJSON ¶ added in v0.3.0
func NewBeautifulLoggerJSON(name string) *BeautifulLogger
NewBeautifulLoggerJSON creates a logger similar to JSON output (caller, fields, timestamp).
func NewBeautifulLoggerMinimal ¶ added in v0.3.0
func NewBeautifulLoggerMinimal(name string) *BeautifulLogger
NewBeautifulLoggerMinimal creates an ultra-minimal logger.
type CustomField ¶
type CustomField = log.CustomField
CustomField represents a field with custom key-value pairs.
type ErrorHandler ¶
type ErrorHandler = log.ErrorHandler
ErrorHandler provides a callback-based error handler with logging.
type Field ¶
Field represents a structured log field.
func MergeFields ¶
MergeFields merges multiple field slices into one.
func SanitizeFields ¶
SanitizeFields removes nil and invalid fields.
func WrapZapField ¶
WrapZapField wraps a zap.Field to implement the Field interface.
func WrapZapFields ¶
WrapZapFields wraps multiple zap.Fields.
type FormatConfig ¶ added in v0.3.0
type FormatConfig = log.FormatConfig
FormatConfig controls what components are shown in the output.
func DefaultFormatConfig ¶ added in v0.3.0
func DefaultFormatConfig() FormatConfig
DefaultFormatConfig provides sensible defaults.
type Logger ¶
Logger represents the logging interface.
func GetGlobalLogger ¶
func GetGlobalLogger() Logger
func NewDevelopmentLogger ¶
func NewDevelopmentLogger() Logger
NewDevelopmentLogger creates a development logger with enhanced colors.
func NewDevelopmentLoggerWithLevel ¶
NewDevelopmentLoggerWithLevel creates a development logger with specified level.
func NewLogger ¶
func NewLogger(config LoggingConfig) Logger
NewLogger creates a new logger with the given configuration.
func NewProductionLogger ¶
func NewProductionLogger() Logger
NewProductionLogger creates a production logger.
type LoggingConfig ¶
type LoggingConfig = log.LoggingConfig
LoggingConfig represents logging configuration.
type LoggingWriter ¶
type LoggingWriter = log.LoggingWriter
LoggingWriter is an io.Writer that logs each write.
type PerformanceMonitor ¶
type PerformanceMonitor = log.PerformanceMonitor
PerformanceMonitor helps monitor performance metrics.
type StructuredLog ¶
type StructuredLog = log.StructuredLog
StructuredLog provides a fluent interface for structured logging.
type TestLogger ¶
type TestLogger = log.TestLogger
TestLogger provides a test logger implementation.