jonesrussell / loggo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

loggo

loggo is a simple logging package for Go applications. It provides structured logging with multiple handlers and context support.

Features:

  • Structured logging with JSON format
  • Multiple handlers for logging to files and stdout
  • Configurable log levels
  • Context support for adding operation IDs to logs
  • Helper function to generate unique operation IDs

Installation:

go get -u github.com/jonesrussell/loggo

Usage:

  1. Create a new logger instance specifying the log file path:
import (
  "github.com/jonesrussell/loggo"
)

logger, err := loggo.NewLogger("/path/to/logfile.log")
if err != nil {
  // handle error
}
  1. Use the logger methods to log messages with different levels:
logger.Debug("Starting application")
logger.Info("Processing request", "user", "john")
logger.Warn("Unexpected error", "error", err)
logger.Error("Failed to connect to database", err)
  1. Add operation IDs to logs for context:
operationID := loggo.NewOperationID()
logger = logger.WithOperation(operationID)

logger.Info("Processing payment", "operationID", operationID, "amount", 100)

Dependencies:

About

License:MIT License


Languages

Language:Go 100.0%