log

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogConfig = LogConfig{
	Log: LogOptionsConfig{
		Console: ConsoleLogConfig{
			Level: "error",
		},
		File: FileLogConfig{
			Enabled: false,
			Path:    "log/$name.$date.log",
			Level:   "info",
		},
		Terraform: TerraformLogConfig{
			Enabled: false,
			Path:    "log/$name.$date.tf.log",
			Level:   "trace",
		},
	},
}

DefaultLogConfig provides the default logging configuration.

Functions

func ConfigureDefault

func ConfigureDefault(configFile string, w io.Writer)

ConfigureDefault configures the default logger using the provided configuration file and writer. If an error occurs during configuration, it falls back to the default logger.

func Debug

func Debug(msg interface{}, keyvals ...interface{})

Debug logs a debug message using the default logger.

func DebugEnvOverride

func DebugEnvOverride() bool

DebugEnvOverride checks if the DEBUG environment variable is set to "true" or "1". If set, all loggers will be overridden to debug level regardless of the configured thresholds.

func Error

func Error(msg interface{}, keyvals ...interface{})

Error logs an error message using the default logger.

func Info

func Info(msg interface{}, keyvals ...interface{})

Info logs an informational message using the default logger.

func SetDefault

func SetDefault(logger AppLogger)

SetDefault sets the provided logger as the default global logger.

func Sync

func Sync() error

Sync flushes any buffered log entries from the default logger.

func Warn

func Warn(msg interface{}, keyvals ...interface{})

Warn logs a warning message using the default logger.

Types

type AppLogger

type AppLogger interface {
	Sync() error
	Debug(msg interface{}, keyvals ...interface{})
	Info(msg interface{}, keyvals ...interface{})
	Warn(msg interface{}, keyvals ...interface{})
	Error(msg interface{}, keyvals ...interface{})
	LogEvent(event fxevent.Event)
}

AppLogger defines the interface for application loggers.

func Default

func Default() AppLogger

Default returns the default global logger instance. It initializes the logger if it has not been set already.

func NewZapLogger

func NewZapLogger(cfg LogConfig, w io.Writer) AppLogger

NewZapLogger creates a new instance of ZapLogger with the provided configuration and writer.

type ConsoleLogConfig

type ConsoleLogConfig struct {
	Level string `koanf:"level"`
}

ConsoleLogConfig represents the configuration for console logging.

type FileLogConfig

type FileLogConfig struct {
	Enabled bool   `koanf:"enabled"`
	Path    string `koanf:"path"`
	Level   string `koanf:"level"`
}

FileLogConfig represents the configuration for file-based logging.

type FxLogger

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

FxLogger is a logger implementation for Uber FX that uses a fallback logger until the default logger is configured.

func NewFxLogger

func NewFxLogger() *FxLogger

NewFxLogger creates a new FxLogger instance. It uses the system's default logger if debugging is enabled, or a no-op logger otherwise. This suppresses initial DI container logs until the logger is fully configured.

func (*FxLogger) LogEvent

func (l *FxLogger) LogEvent(event fxevent.Event)

LogEvent logs an fxevent.Event. If the default logger is not yet configured, it uses the fallback logger.

type LogConfig

type LogConfig struct {
	Name string           `koanf:"name"`
	Log  LogOptionsConfig `koanf:"log"`
}

LogConfig represents the configuration for logging, including log name and options.

func NewLogConfig

func NewLogConfig(path string) (LogConfig, error)

NewLogConfig loads the logging configuration from the specified file path. If the path is empty or an error occurs, it returns the default configuration.

type LogOptionsConfig

type LogOptionsConfig struct {
	Console   ConsoleLogConfig   `koanf:"console"`
	File      FileLogConfig      `koanf:"file"`
	Terraform TerraformLogConfig `koanf:"terraform"`
}

LogOptionsConfig contains configuration options for different logging outputs.

type TerraformLogConfig

type TerraformLogConfig struct {
	Enabled bool   `koanf:"enabled"`
	Path    string `koanf:"path"`
	Level   string `koanf:"level"`
}

TerraformLogConfig represents the configuration for Terraform-specific logging.

type ZapLogger

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

ZapLogger is a logger implementation using Uber's Zap library.

func (*ZapLogger) Debug

func (l *ZapLogger) Debug(msg interface{}, keyvals ...interface{})

Debug prints a debug message with optional key-value pairs.

func (*ZapLogger) Error

func (l *ZapLogger) Error(msg interface{}, keyvals ...interface{})

Error prints an error message with optional key-value pairs.

func (*ZapLogger) Info

func (l *ZapLogger) Info(msg interface{}, keyvals ...interface{})

Info prints an informational message with optional key-value pairs.

func (*ZapLogger) LogEvent

func (l *ZapLogger) LogEvent(event fxevent.Event)

LogEvent logs an fxevent.Event using the underlying fxevent.Logger.

func (*ZapLogger) Sync

func (l *ZapLogger) Sync() error

Sync flushes any buffered log entries.

func (*ZapLogger) Warn

func (l *ZapLogger) Warn(msg interface{}, keyvals ...interface{})

Warn prints a warning message with optional key-value pairs.

Jump to

Keyboard shortcuts

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