builtins

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package builtins provides built-in plugin implementations for the vcfg configuration system. This package automatically registers all built-in plugins when imported, making them available for use without manual registration.

Package builtins provides built-in plugins for the vcfg configuration system. This file implements a comprehensive logger plugin that supports multiple output formats, destinations, and log levels with structured logging capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogger

func GetLogger() *slog.Logger

GetLogger returns the current global logger instance for application use. If no logger has been configured, it returns the default slog logger. This function is thread-safe and can be called from multiple goroutines.

Returns:

  • *slog.Logger: The current global logger or default logger if none is set

Types

type LoggerConfig

type LoggerConfig struct {
	// BaseConfig embeds the common plugin configuration
	plugins.BaseConfig `koanf:",squash"`
	// Level sets the minimum log level (debug, info, warn, error)
	Level string `koanf:"level" default:"info"`
	// Format specifies the log output format (json, text)
	Format string `koanf:"format" default:"json"`
	// Output determines where logs are written (stdout, stderr, file, both)
	Output string `koanf:"output" default:"stdout"`
	// FilePath specifies the log file path when output includes file
	FilePath string `koanf:"file_path" default:"./app.log"`
	// AddSource includes source file information in log entries
	AddSource bool `koanf:"add_source" default:"false"`
	// EnableRotation enables log file rotation
	EnableRotation bool `koanf:"enable_rotation" default:"false"`
	// RotateInterval sets the rotation interval (daily, hourly)
	RotateInterval string `koanf:"rotate_interval" default:"daily"`
	// MaxFileSize sets the maximum file size in bytes before rotation (0 = no size limit)
	MaxFileSize int64 `koanf:"max_file_size" default:"524288000"` // 500MB
	// MaxAge sets the maximum number of days to retain old log files
	MaxAge int `koanf:"max_age" default:"7"`
	// TimeFormat sets the time format for rotated file names
	TimeFormat string `koanf:"time_format" default:"2006-01-02"`
}

LoggerConfig represents the configuration for the logger plugin. It defines all configurable aspects of the logging behavior including output format, destination, log level, rotation settings, and additional options.

type LoggerPlugin

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

LoggerPlugin implements the logger plugin that provides structured logging capabilities with configurable output formats, destinations, and rotation.

func (*LoggerPlugin) Reload

func (p *LoggerPlugin) Reload(ctx context.Context, config any) error

Reload implements the plugins.Plugin interface by reloading the logger with new configuration. It gracefully shuts down the current logger and reinitializes it with the new settings.

Parameters:

  • ctx: Context for the reload operation
  • config: New LoggerConfig instance

Returns:

  • error: An error if reload fails, nil otherwise

func (*LoggerPlugin) Shutdown

func (p *LoggerPlugin) Shutdown(ctx context.Context) error

Shutdown implements the plugins.Plugin interface by gracefully shutting down the logger plugin. It closes any open file handles and cleans up resources.

Parameters:

  • ctx: Context for the shutdown operation

Returns:

  • error: An error if shutdown fails, nil otherwise

func (*LoggerPlugin) Startup

func (p *LoggerPlugin) Startup(ctx context.Context, config any) error

Startup implements the plugins.Plugin interface by initializing the logger with the provided configuration. It sets up the log level, format, output destination, and creates the appropriate handlers.

Parameters:

  • ctx: Context for the startup operation
  • config: LoggerConfig instance containing the logger configuration

Returns:

  • error: An error if initialization fails, nil otherwise

Jump to

Keyboard shortcuts

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