Documentation
¶
Overview ¶
Package logging handles setup and configuration of application logging.
Package logging provides header sanitization to prevent secret leakage in logs.
Index ¶
- Variables
- func Debugf(format string, v ...interface{})
- func DefaultLogPath() (string, error)
- func Errorf(format string, v ...interface{})
- func GetLogger() *logrus.Logger
- func GetWriter() io.Writer
- func Infof(format string, v ...interface{})
- func Init(cfg *config.LoggingConfig) (func(), error)
- func InitToSilent()
- func InitToStderr()
- func InitToStdout()
- func InitWithPath(logPath string) (func(), error)
- func LogsDir() (string, error)
- func SanitizeHeaders(headers http.Header) map[string][]string
- func SanitizeHeadersString(headers http.Header) string
- func StreamDebugf(format string, v ...interface{})
- func Streamf(format string, v ...interface{})
- func Warnf(format string, v ...interface{})
- type SyncingFileWriter
Constants ¶
This section is empty.
Variables ¶
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 DefaultLogPath ¶
DefaultLogPath returns the default log file path. Note: For per-instance logging, use GetLogPathWithInstance instead.
func GetWriter ¶
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 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 InitWithPath ¶
InitWithPath initializes logging with a specific file path. This is a convenience function for programmatic setup.
func SanitizeHeaders ¶
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 ¶
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).
Types ¶
type SyncingFileWriter ¶
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.