loggo

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 5 Imported by: 6

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 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 slog.Level) (LoggerInterface, error)

type MockLogger added in v0.1.2

type MockLogger struct {
	// You can add more fields if needed
	InfoMessages  []string
	DebugMessages []string
	ErrorMessages []string
}

func NewMockLogger added in v0.1.2

func NewMockLogger() *MockLogger

func (*MockLogger) Debug added in v0.1.2

func (m *MockLogger) Debug(msg string, args ...interface{})

func (*MockLogger) Error added in v0.1.2

func (m *MockLogger) Error(msg string, err error, args ...interface{})

func (*MockLogger) Fatal added in v0.1.2

func (m *MockLogger) Fatal(msg string, err error, args ...interface{})

func (*MockLogger) Info added in v0.1.2

func (m *MockLogger) Info(msg string, args ...interface{})

func (*MockLogger) IsDebugEnabled added in v0.1.2

func (m *MockLogger) IsDebugEnabled() bool

func (*MockLogger) Warn added in v0.1.2

func (m *MockLogger) Warn(msg string, args ...interface{})

func (*MockLogger) WithOperation added in v0.1.2

func (m *MockLogger) WithOperation(operationID string) LoggerInterface

Jump to

Keyboard shortcuts

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