Documentation
¶
Index ¶
- Variables
- func Close()
- func DebugS(message string, fields ...map[string]interface{})
- func ErrorS(message string, fields ...map[string]interface{})
- func FatalS(message string, fields ...map[string]interface{})
- func GetActiveSessionLogPaths() map[string]string
- func GetConfigDir() (string, error)
- func GetGlobalLogPath() string
- func GetLogDir(cfg *LogConfig) (string, error)
- func GetLogFilePath(cfg *LogConfig) (string, error)
- func GetSessionLogFilePath(cfg *LogConfig, sessionID string) (string, error)
- func GetTestLogDir() (string, error)
- func InfoS(message string, fields ...map[string]interface{})
- func Initialize(daemon bool)
- func InitializeForTests(fileLevel LogLevel, consoleLevel LogLevel)
- func InitializeWithConfig(daemon bool, externalConfig interface{})
- func LogForSession(sessionID, level, format string, v ...interface{})
- func LogSessionPathsToStderr()
- func WarningS(message string, fields ...map[string]interface{})
- type Every
- type LogConfig
- type LogLevel
- type SessionLoggers
- type StructuredLogEntry
- type StructuredLogger
- func (sl *StructuredLogger) Debug(message string, fields ...map[string]interface{})
- func (sl *StructuredLogger) Error(message string, fields ...map[string]interface{})
- func (sl *StructuredLogger) Fatal(message string, fields ...map[string]interface{})
- func (sl *StructuredLogger) Info(message string, fields ...map[string]interface{})
- func (sl *StructuredLogger) Log(level LogLevel, message string, fields map[string]interface{})
- func (sl *StructuredLogger) LogWithFields(level LogLevel, message string, fields map[string]interface{})
- func (sl *StructuredLogger) Warning(message string, fields ...map[string]interface{})
Constants ¶
This section is empty.
Variables ¶
var ( WarningLog *log.Logger InfoLog *log.Logger ErrorLog *log.Logger DebugLog *log.Logger )
var ( // ErrSessionLogsDisabled is returned when session logs are disabled in config ErrSessionLogsDisabled = fmt.Errorf("session logs disabled in config") )
Functions ¶
func GetActiveSessionLogPaths ¶
GetActiveSessionLogPaths returns the paths to all active session log files
func GetConfigDir ¶
GetConfigDir returns the path to the application's configuration directory
func GetGlobalLogPath ¶
func GetGlobalLogPath() string
GetGlobalLogPath returns the path to the global log file
func GetLogFilePath ¶
GetLogFilePath returns the full path to the log file
func GetSessionLogFilePath ¶
GetSessionLogFilePath returns the full path to a session-specific log file
func GetTestLogDir ¶
GetTestLogDir returns the directory where test logs should be stored Test logs are isolated in a dedicated subdirectory for easy cleanup
func Initialize ¶
func Initialize(daemon bool)
func InitializeForTests ¶
InitializeForTests sets up logging specifically for test environments with dual-stream configuration. This allows DEBUG logs to go to file while ERROR logs appear in console for immediate visibility.
Parameters:
- fileLevel: Minimum level for file logging (typically DEBUG to capture everything)
- consoleLevel: Minimum level for console logging (typically ERROR to avoid noise)
Example:
log.InitializeForTests(log.DEBUG, log.ERROR) // DEBUG→file, ERROR→console
func InitializeWithConfig ¶
func InitializeWithConfig(daemon bool, externalConfig interface{})
InitializeWithConfig sets up logging with the provided configuration.
func LogForSession ¶
func LogForSession(sessionID, level, format string, v ...interface{})
LogForSession logs a message to the session-specific log file
func LogSessionPathsToStderr ¶
func LogSessionPathsToStderr()
LogSessionPathsToStderr outputs session log file paths to stderr on exit
Types ¶
type Every ¶
type Every struct {
// contains filtered or unexported fields
}
Every is used to log at most once every timeout duration.
type LogConfig ¶
type LogConfig struct {
LogsEnabled bool
LogsDir string
LogMaxSize int
LogMaxFiles int
LogMaxAge int
LogCompress bool
UseSessionLogs bool
LogLevel LogLevel // Deprecated: Use FileLevel and ConsoleLevel instead
StructuredLogs bool
PrettyLogs bool // For development - formats JSON logs for readability
// Dual-stream logging configuration (file + console)
ConsoleEnabled bool // Enable/disable console output (default: true)
ConsoleLevel LogLevel // Minimum level for console (default: ERROR for tests, INFO for production)
FileEnabled bool // Enable/disable file output (default: true)
FileLevel LogLevel // Minimum level for file (default: DEBUG)
}
LogConfig holds logging configuration
func ConfigToLogConfig ¶
func ConfigToLogConfig(externalConfig interface{}) *LogConfig
ConfigToLogConfig converts an external config to our internal LogConfig
func DefaultLogConfig ¶
func DefaultLogConfig() *LogConfig
DefaultLogConfig returns the default logging configuration
type LogLevel ¶
type LogLevel int
LogLevel represents the severity of a log entry
func ParseLogLevel ¶
ParseLogLevel parses a string into a LogLevel
type SessionLoggers ¶
type SessionLoggers struct {
WarningLog *log.Logger
InfoLog *log.Logger
ErrorLog *log.Logger
DebugLog *log.Logger
LogFile io.Closer
}
SessionLoggers holds the loggers for a specific session
func GetSessionLoggers ¶
func GetSessionLoggers(sessionID string) (*SessionLoggers, error)
GetSessionLoggers creates or retrieves loggers for a specific session
type StructuredLogEntry ¶
type StructuredLogEntry struct {
Timestamp time.Time `json:"timestamp"`
Level string `json:"level"`
Message string `json:"message"`
SessionID string `json:"session_id,omitempty"`
Component string `json:"component,omitempty"`
Function string `json:"function,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Fields map[string]interface{} `json:"fields,omitempty"`
Error string `json:"error,omitempty"`
}
StructuredLogEntry represents a structured log entry
type StructuredLogger ¶
type StructuredLogger struct {
// contains filtered or unexported fields
}
StructuredLogger provides structured logging functionality
func NewStructuredLogger ¶
func NewStructuredLogger(writer io.Writer, level LogLevel, prettyLog bool) *StructuredLogger
NewStructuredLogger creates a new structured logger
func (*StructuredLogger) Debug ¶
func (sl *StructuredLogger) Debug(message string, fields ...map[string]interface{})
Debug logs a debug message
func (*StructuredLogger) Error ¶
func (sl *StructuredLogger) Error(message string, fields ...map[string]interface{})
Error logs an error message
func (*StructuredLogger) Fatal ¶
func (sl *StructuredLogger) Fatal(message string, fields ...map[string]interface{})
Fatal logs a fatal message
func (*StructuredLogger) Info ¶
func (sl *StructuredLogger) Info(message string, fields ...map[string]interface{})
Info logs an info message
func (*StructuredLogger) Log ¶
func (sl *StructuredLogger) Log(level LogLevel, message string, fields map[string]interface{})
Log writes a structured log entry
func (*StructuredLogger) LogWithFields ¶
func (sl *StructuredLogger) LogWithFields(level LogLevel, message string, fields map[string]interface{})
LogWithFields logs a message with additional fields
func (*StructuredLogger) Warning ¶
func (sl *StructuredLogger) Warning(message string, fields ...map[string]interface{})
Warning logs a warning message