Documentation
¶
Overview ¶
Package slogmanager provides a centralized logging management system using slog. It supports multiple writers and concurrent access to logging facilities.
Package writer provides a customizable writer implementation for structured logging with support for both JSON and text formats using the slog package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the central structure for managing multiple log writers and handlers. It provides thread-safe operations for managing logging configuration.
func New ¶
func New() *Manager
New creates and initializes a new Manager instance. It initializes an empty map of writers that can be populated later.
Returns:
- *Manager: A new manager instance ready for use.
func (*Manager) AddWriter ¶
AddWriter registers a new writer with the manager. It's thread-safe to add a writer and after updates logger
Parameters:
- name: The name of writer to add to the manager
- writer: The writer instance to add to the manager.
func (*Manager) Logger ¶
Logger returns the current logger instance from the manager. It provides thread-safe access to the logger.
Returns:
- *slog.Logger: The current logger instance.
func (*Manager) RemoveWriter ¶
RemoveWriter unregisters a writer from the manager. It's thread-safe and automatically updates the logger configuration after removing the writer
Parameters:
- name: The writer's name to remove from the manager.
type Option ¶
type Option func(*writerConfig)
Option defines the function type for writer configuration options. It follows the functional options pattern for flexible and extensible configuration.
func WithJSONFormat ¶
func WithJSONFormat() Option
WithJSONFormat returns an Option that sets the writer format to JSON. This is useful when structured logging output is needed.
Returns:
- Option: A function that sets UseJSON to true when applied.
func WithSlogHandlerOptions ¶
func WithSlogHandlerOptions(h *slog.HandlerOptions) Option
WithSlogHandlerOptions returns an Option that sets custom slog handler options. These options can configure various aspects of log handling like level filtering, time formats, and source file information.
Parameters:
- h: Pointer to slog.HandlerOptions containing desired handler configuration
Returns:
- Option: A function that applies the provided handler options when used.
func WithTextFormat ¶
func WithTextFormat() Option
WithTextFormat returns an Option that sets the writer format to text. This is the default format if no format option is specified.
Returns:
- Option: A function that sets UseJSON to false when applied.
type Writer ¶
Writer represents a custom writer that implements io.Writer interface and includes configuration options for logging format and handling.
func NewWriter ¶
NewWriter creates a new Writer instance with specified options. It uses the functional options pattern for flexible configuration.
Parameters:
- writer: An io.Writer interface implementation for actual writing
- opts: Variable number of Option functions for configuration
Returns:
- *Writer: A configured Writer instance.