Documentation
¶
Overview ¶
Package logging provides a simple logging library with support for multiple log levels, custom prefixes, colored output, and customizable output streams.
Index ¶
Constants ¶
const ( ColorReset = "\033[0m" // Reset to default color ColorBlue = "\033[34m" // Blue color for INFO level logs ColorGreen = "\033[32m" // Green color for DEBUG level logs ColorYellow = "\033[33m" // Yellow color for WARN level logs ColorRed = "\033[31m" // Red color for ERROR level logs )
ANSI color codes for different log levels
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogLevel ¶
type LogLevel int
LogLevel represents the severity level of a log message.
const ( DEBUG LogLevel = iota // DEBUG is used for detailed information during development. INFO // INFO is used for general informational messages. WARN // WARN is used for warnings that are not critical. ERROR // ERROR is used for critical error messages. )
Defined log levels in increasing order of severity.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a configurable logging instance that supports multiple log levels, optional colored output, and custom prefixes for log messages.
func NewLogger ¶
NewLogger creates and returns a new Logger instance with the specified prefix, minimum log level, and output destination. If output is nil, os.Stdout is used as the default destination.
Parameters:
- prefix: A string prefix that will appear in all log messages.
- minLevel: The minimum log level for a message to be logged.
- output: The io.Writer to which log messages will be written.
Returns:
A pointer to a configured Logger instance.
func (*Logger) Debug ¶
Debug logs a message at the DEBUG level.
Parameters:
- message: The debug message to log.
func (*Logger) Error ¶
Error logs a message at the ERROR level.
Parameters:
- message: The error message to log.
func (*Logger) Info ¶
Info logs a message at the INFO level.
Parameters:
- message: The informational message to log.
func (*Logger) SetRedactionRegex ¶ added in v1.26.0
SetRedactionRegex allows users to define custom regex patterns for redaction. This provides more flexibility than SetRedactionRules.
Parameters:
- patterns: A map where keys are regex patterns and values are replacement strings.
func (*Logger) SetRedactionRules ¶ added in v1.26.0
SetRedactionRules configures the logger to redact sensitive information based on the provided patterns. Each key represents a pattern to match, and the value is the replacement text.
Parameters:
- rules: A map where keys are patterns (e.g., "password=", "credit_card=") and values are replacement strings (e.g., "***REDACTED***").
type RedactionRule ¶ added in v1.26.0
type RedactionRule struct {
Pattern *regexp.Regexp // Regex pattern to match sensitive data
Replacement string // Replacement text for matched patterns
}
RedactionRule defines how to redact sensitive information