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 ¶
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func GetLogger() *logrus.Logger
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func InitLogger(config Config) error
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func WithField(key string, value interface{}) *logrus.Entry
- func WithFields(fields logrus.Fields) *logrus.Entry
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs a formatted message at debug level
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a formatted message at error level
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs a formatted message at fatal level and exits
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a formatted message at info level
func InitLogger ¶
InitLogger initializes the global logger with the given configuration
func Warnf ¶
func Warnf(format string, args ...interface{})
Warnf logs a formatted message at warning level
Types ¶
Click to show internal directories.
Click to hide internal directories.