logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logger provides structured logging configuration for clibot.

This package initializes and configures logrus for structured logging with support for:

  • Multiple log levels (debug, info, warn, error)
  • File output with automatic log rotation
  • Console output with color formatting
  • JSON format for production environments

Configuration

Logging behavior is configured through the Config struct:

  • Level: Minimum log level to capture (default: "info")
  • File: Path to log file (optional)
  • MaxSize: Maximum size of single log file in MB (default: 100)
  • MaxBackups: Maximum number of old log files to keep (default: 5)
  • MaxAge: Maximum number of days to retain old logs (default: 30)
  • Compress: Whether to compress rotated logs (default: true)
  • EnableStdout: Also output to stdout (default: true)

Usage

// Initialize logger with configuration
config := logger.Config{
    Level: "debug",
    File: "/var/log/clibot/app.log",
    EnableStdout: true,
}
if err := logger.InitLogger(config); err != nil {
    log.Fatal(err)
}

// Use structured logging
logger.WithFields(logrus.Fields{
    "user": "alice",
    "action": "login",
}).Info("User logged in")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug logs a message at debug level

func Debugf

func Debugf(format string, args ...interface{})

Debugf logs a formatted message at debug level

func Error

func Error(args ...interface{})

Error logs a message at error level

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs a formatted message at error level

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at fatal level and exits

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs a formatted message at fatal level and exits

func GetLogger

func GetLogger() *logrus.Logger

GetLogger returns the global logger instance

func Info

func Info(args ...interface{})

Info logs a message at info level

func Infof

func Infof(format string, args ...interface{})

Infof logs a formatted message at info level

func InitLogger

func InitLogger(config Config) error

InitLogger initializes the global logger with the given configuration

func Warn

func Warn(args ...interface{})

Warn logs a message at warning level

func Warnf

func Warnf(format string, args ...interface{})

Warnf logs a formatted message at warning level

func WithField

func WithField(key string, value interface{}) *logrus.Entry

WithField returns a logger entry with a single field

func WithFields

func WithFields(fields logrus.Fields) *logrus.Entry

WithFields returns a logger entry with structured fields

Types

type Config

type Config struct {
	Level        string
	File         string
	MaxSize      int
	MaxBackups   int
	MaxAge       int
	Compress     bool
	EnableStdout bool
}

Config represents the configuration for the logger

Jump to

Keyboard shortcuts

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