logger

package
v0.0.0-...-e5d423c Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package logger provides structured logging using zerolog.

This package implements production-ready logging with: - Structured JSON logging for production (machine-parsable) - Pretty console output for development (human-readable) - Component-specific loggers (security, websocket, webhook, etc.) - Configurable log levels (debug, info, warn, error, fatal)

SECURITY ENHANCEMENT (2025-11-14): Added structured logging to replace fmt.Printf and log.Printf calls. Benefits: - Machine-parsable logs for security monitoring and alerting - Consistent log format across all components - Automatic field extraction for log aggregation (e.g., Elasticsearch) - Performance: Zero-allocation JSON logging in production

Usage:

// Initialize once in main()
logger.Initialize("info", false) // production: JSON output
logger.Initialize("debug", true) // development: pretty output

// Use component-specific loggers
logger.Security().Warn().
  Str("user_id", "user123").
  Str("ip", "203.0.113.42").
  Msg("Failed MFA attempt")

// Use global logger for general events
logger.Log.Info().Msg("Application started")

Index

Constants

This section is empty.

Variables

View Source
var (
	Log zerolog.Logger
)

Global logger instance - use this for general application logging.

For component-specific logging, use the helper functions like Security(), WebSocket(), etc. to get loggers with pre-configured component tags.

Functions

func Database

func Database() *zerolog.Logger

Database creates a logger for database events

func GetLogger

func GetLogger() *zerolog.Logger

GetLogger returns the global logger instance

func HTTP

func HTTP() *zerolog.Logger

HTTP creates a logger for HTTP request events

func Initialize

func Initialize(level string, pretty bool)

Initialize sets up the global logger with the specified level and output format.

This function should be called once at application startup before any logging occurs.

Parameters:

  • level: Log level as string ("debug", "info", "warn", "error", "fatal", "panic") Defaults to "info" if invalid level provided
  • pretty: If true, use human-readable console output (development) If false, use JSON output (production)

Production Configuration:

logger.Initialize("info", false)
Output: {"level":"info","service":"streamspace-api","time":1699999999,"message":"User logged in"}

Development Configuration:

logger.Initialize("debug", true)
Output: 10:30:00 INF User logged in service=streamspace-api

Log Levels (from most to least verbose):

  • debug: Detailed debugging information
  • info: General informational messages
  • warn: Warning messages (potential issues)
  • error: Error messages (handled errors)
  • fatal: Fatal errors (application exits)
  • panic: Panic errors (application crashes)

func Integration

func Integration() *zerolog.Logger

Integration creates a logger for integration events

func Security

func Security() *zerolog.Logger

Security creates a logger for security events

func WebSocket

func WebSocket() *zerolog.Logger

WebSocket creates a logger for WebSocket events

func Webhook

func Webhook() *zerolog.Logger

Webhook creates a logger for webhook events

Types

This section is empty.

Jump to

Keyboard shortcuts

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