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:
- 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
}
- 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)
- Add operation IDs to logs for context:
operationID := loggo.NewOperationID()
logger = logger.WithOperation(operationID)
logger.Info("Processing payment", "operationID", operationID, "amount", 100)
Dependencies: