logging

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package logging handles setup and configuration of application logging.

Package logging provides header sanitization to prevent secret leakage in logs.

Index

Constants

This section is empty.

Variables

View Source
var SensitiveHeaders = map[string]bool{
	"authorization":            true,
	"x-api-key":                true,
	"x-auth-token":             true,
	"cookie":                   true,
	"set-cookie":               true,
	"proxy-authorization":      true,
	"x-amz-security-token":     true,
	"x-goog-iam-authorization": true,
	"apikey":                   true,
	"x-bigmodel-api-key":       true,
	"x-openrouter-api-key":     true,
}

SensitiveHeaders lists headers that contain secrets and must be redacted. These header names are compared case-insensitively.

Functions

func Debugf

func Debugf(format string, v ...interface{})

Debugf logs a debug message.

func DefaultLogPath

func DefaultLogPath() (string, error)

DefaultLogPath returns the default log file path. Note: For per-instance logging, use GetLogPathWithInstance instead.

func Errorf

func Errorf(format string, v ...interface{})

Errorf logs an error message.

func GetLogger

func GetLogger() *logrus.Logger

GetLogger returns the underlying logrus logger for advanced usage.

func GetWriter

func GetWriter() io.Writer

GetWriter returns the current log writer. This is provided for compatibility with http.Server.ErrorLog. Returns io.Discard if logging has not been initialized.

func Infof

func Infof(format string, v ...interface{})

Infof logs an info message.

func Init

func Init(cfg *config.LoggingConfig) (func(), error)

Init initializes logging based on the provided configuration. It redirects the logrus output to the configured destination. Logging output is controlled by the Destination configuration.

The function returns an error if the log destination cannot be initialized, or a cleanup function that should be called on shutdown to close any open files.

func InitToSilent

func InitToSilent()

InitToSilent discards all log output.

func InitToStderr

func InitToStderr()

InitToStderr redirects logs to stderr.

func InitToStdout

func InitToStdout()

InitToStdout redirects logs to stdout.

func InitWithPath

func InitWithPath(logPath string) (func(), error)

InitWithPath initializes logging with a specific file path. This is a convenience function for programmatic setup.

func LogsDir

func LogsDir() (string, error)

LogsDir returns the logs directory path.

func SanitizeHeaders

func SanitizeHeaders(headers http.Header) map[string][]string

SanitizeHeaders returns a copy of headers with sensitive values redacted. This is used to prevent API keys, tokens, and other secrets from appearing in logs.

func SanitizeHeadersString

func SanitizeHeadersString(headers http.Header) string

SanitizeHeadersString returns a string representation of headers with redacted secrets. The output format matches Go's default map printing style for compatibility with existing logs.

func StreamDebugf

func StreamDebugf(format string, v ...interface{})

StreamDebugf logs detailed streaming debug information (DEBUG level).

func Streamf

func Streamf(format string, v ...interface{})

Streamf logs a streaming-related message (INFO level by default). These are verbose per-event logs that should be filtered at DEBUG level.

func Warnf

func Warnf(format string, v ...interface{})

Warnf logs a warning message.

Types

type SyncingFileWriter

type SyncingFileWriter struct {
	*os.File
}

SyncingFileWriter wraps an *os.File and syncs to disk after each write. This ensures log messages are immediately written to disk and not buffered.

func (*SyncingFileWriter) Close

func (s *SyncingFileWriter) Close() error

Close closes the underlying file.

func (*SyncingFileWriter) Write

func (s *SyncingFileWriter) Write(p []byte) (n int, err error)

Write writes data to the file and immediately syncs to disk. This prevents log buffering issues where logs might not appear in the file until the buffer is flushed or the program exits.

Jump to

Keyboard shortcuts

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