Documentation
¶
Overview ¶
Package titanlog provides a simple, leveled structured logging system. It supports log levels, custom outputs, and structured fields.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fields ¶
type Fields map[string]interface{}
Fields is a type alias for a map of key-value pairs used in structured logging. Keys should be strings, and values can be of any type.
type Formatter ¶ added in v0.1.2
Formatter defines the interface that all log formatters must implement.
type JSONFormatter ¶ added in v0.1.2
type JSONFormatter struct{}
JSONFormatter formats logs as a JSON object.
type Level ¶
type Level int
Level represents the severity of a log message. Higher values indicate more severe events.
const ( // DebugLevel is for verbose output, useful for developers. DebugLevel Level = iota // InfoLevel is for standard operational messages. InfoLevel // WarnLevel is for non-critical issues that should be looked at. WarnLevel // ErrorLevel is for runtime errors that require attention. ErrorLevel // FatalLevel is for severe errors that may cause the application to crash. FatalLevel )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the main struct that holds the configuration for logging. It is safe for concurrent use.
func New ¶
New creates a new Logger instance. The threshold determines the minimum log level to output (e.g., if set to InfoLevel, DebugLevel logs are ignored). The output parameter specifies where logs should be written (e.g., os.Stdout or a file).
func (*Logger) Debug ¶
Debug logs a message at DebugLevel. These are typically used for verbose output during development.
func (*Logger) Error ¶
Error logs a message at ErrorLevel. These indicate runtime errors that require attention.
func (*Logger) Fatal ¶
Fatal logs a message at FatalLevel. These indicate severe errors that may cause the application to crash or become unusable.
func (*Logger) Info ¶
Info logs a message at InfoLevel. These are used for standard operational events.
func (*Logger) SetFormatter ¶ added in v0.1.2
SetFormatter allows changing the logging format (e.g., JSON or Text) at runtime.
func (*Logger) Warn ¶
Warn logs a message at WarnLevel. These indicate non-critical issues that should be reviewed.
func (*Logger) WithFields ¶
WithFields creates a new Logger instance with the provided fields added to the existing context.
This method returns a copy of the logger; the original logger is not modified. This allows for creating context-specific loggers (e.g., per-request or per-user) without affecting the global logger.
type TextFormatter ¶ added in v0.1.2
type TextFormatter struct{}
TextFormatter formats logs as "TIME LEVEL key=value msg"