loggo

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 5 Imported by: 18

README

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:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level added in v0.2.0

type Level slog.Level

Define a custom Level type

const (
	LevelDebug Level = Level(slog.LevelDebug)
	LevelInfo  Level = Level(slog.LevelInfo)
	LevelWarn  Level = Level(slog.LevelWarn)
	LevelError Level = Level(slog.LevelError)
)

Define log level constants

type Logger

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

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(msg string, err error, args ...interface{})

func (*Logger) Fatal added in v0.1.2

func (l *Logger) Fatal(msg string, err error, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(msg string, args ...interface{})

func (*Logger) IsDebugEnabled added in v0.1.2

func (l *Logger) IsDebugEnabled() bool

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...interface{})

func (*Logger) WithOperation

func (l *Logger) WithOperation(operationID string) LoggerInterface

type LoggerInterface

type LoggerInterface interface {
	Debug(msg string, args ...interface{})
	Info(msg string, args ...interface{})
	Warn(msg string, args ...interface{})
	Error(msg string, err error, args ...interface{})
	Fatal(msg string, err error, args ...interface{})
	WithOperation(operationID string) LoggerInterface
	IsDebugEnabled() bool
}

func NewLogger

func NewLogger(logFilePath string, level Level) (LoggerInterface, error)

Jump to

Keyboard shortcuts

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