logger

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package logger provides a comprehensive logging system designed for TUI applications. It supports multiple log levels, file-based logging, and configurable output destinations. The logger is designed to avoid stdout interference with terminal user interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGlobalLogger

func GetGlobalLogger() interfaces.Logger

GetGlobalLogger returns the global logger instance If not initialized, it creates a simple logger with Info level.

func GetPackageLogger

func GetPackageLogger(packageName string) interfaces.Logger

GetPackageLogger returns a logger for a specific package using the global cache directory This ensures all packages log to the same unified log file.

func InitGlobalLogger

func InitGlobalLogger(level Level, cacheDir string) error

InitGlobalLogger initializes the global logger with the specified cache directory This should be called early in application initialization.

func InitGlobalLoggerWithValidation

func InitGlobalLoggerWithValidation(level Level, cacheDir string) error

InitGlobalLoggerWithValidation initializes the global logger with cache directory validation This is a convenience function that validates the cache directory before initializing.

func SetDebugEnabled

func SetDebugEnabled(enabled bool)

SetDebugEnabled sets the global debug flag for the logger package. This should be called during application initialization to enable debug logging.

Types

type Config

type Config struct {
	Level      Level
	Output     io.Writer
	LogToFile  bool
	LogFile    string
	TimeFormat string
}

Config holds configuration for the logger.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default logger configuration.

type Level

type Level int

Level represents the logging level.

const (
	LevelDebug Level = iota
	LevelInfo
	LevelError
)

func (Level) String

func (l Level) String() string

String returns the string representation of the log level.

type Logger

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

Logger implements the interfaces.Logger interface with configurable output and levels.

func GetPackageLoggerConcrete

func GetPackageLoggerConcrete(packageName string) *Logger

GetPackageLoggerConcrete returns a concrete Logger instance for packages that need the specific type This ensures all packages log to the same unified log file while maintaining type compatibility.

func NewDualLogger

func NewDualLogger(level Level, logFile string) (*Logger, error)

NewDualLogger creates a logger that outputs to both stdout and a file.

func NewFileLogger

func NewFileLogger(level Level, logFile string) (*Logger, error)

NewFileLogger creates a logger that outputs to a file with the given level.

func NewInternalLogger

func NewInternalLogger(level Level, cacheDir string) (*Logger, error)

NewInternalLogger creates a logger that stores logs in the specified cache directory This is designed for TUI applications where stdout logging would interfere with the UI.

func NewLogger

func NewLogger(config *Config) (*Logger, error)

NewLogger creates a new logger with the given configuration.

func NewSimpleLogger

func NewSimpleLogger(level Level) *Logger

NewSimpleLogger creates a logger that outputs to stdout with the given level.

func (*Logger) Close

func (l *Logger) Close() error

Close closes any file handles if the logger is writing to a file.

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

Debug logs a debug message (implements interfaces.Logger).

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

Error logs an error message (implements interfaces.Logger).

func (*Logger) GetLevel

func (l *Logger) GetLevel() Level

GetLevel returns the current logging level.

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

Info logs an info message (implements interfaces.Logger).

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel changes the logging level.

Jump to

Keyboard shortcuts

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