Documentation
¶
Index ¶
Constants ¶
const DefaultFileHookLayout = "20060102_log.json"
Variables ¶
var ErrInvalidConfig = errors.New("invalid config")
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Level string `json:"level" yaml:"level"`
File struct {
Path string `json:"path" yaml:"path"`
Layout string `json:"layout" yaml:"layout"`
} `json:"file" yaml:"file"`
Discord discordbotrus.Config `json:"discord" yaml:"discord"`
}
Config represents the configuration structure for the logger. It includes settings for log level and file output configuration.
type Logger ¶
Logger wraps logrus.Logger with additional configuration and methods.
func New ¶
func New() *Logger
New creates and returns a new Logger instance with default JSON formatter. The returned logger has no output set by default (uses stderr).
func (*Logger) AddOutput ¶
AddOutput adds additional output writer to the logger. This allows writing logs to multiple destinations simultaneously. The new writer will be used in addition to any existing outputs.
func (*Logger) Close ¶
Close implements the io.Closer interface for the Logger. Currently, it doesn't perform any cleanup but is provided for future compatibility.
func (*Logger) SetConfig ¶
SetConfig applies a new configuration to the Logger and configures all required outputs. It handles the following configuration aspects:
- Core logger settings (log level)
- File output configuration (if specified)
- Discord hook setup (if configured)
Parameters:
- cfg: Pointer to Config struct containing all logger settings. Must not be nil.
- options: Optional variadic list of Option functions to modify logger behavior.
Returns:
- error: Returns ErrInvalidConfig if cfg is nil or contains invalid settings. Returns file creation errors if file logging is configured. Returns Discord hook initialization errors if Discord logging is configured.
Usage:
err := logger.SetConfig(&Config{
Level: "info",
File: FileConfig{Path: "/var/log", Layout: "2006-01-02.log"},
})
if err != nil {
// handle error
}
Notes:
- This function is not concurrent-safe and should not be called while the logger is in use.
- Replaces all previous configuration when called.
- File outputs are created immediately if specified in config.
- Discord hooks are initialized immediately if configured.