Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLogger ¶
func DefaultLogger() *zap.SugaredLogger
DefaultLogger returns the default logger for the application. It initializes the logger only once, on the first call.
func FromContext ¶
func FromContext(ctx context.Context) *zap.SugaredLogger
FromContext retrieves the logger stored in the context. If no logger is found in the context, the default logger is returned.
func NewLogger ¶
func NewLogger(conf *Config) *zap.SugaredLogger
NewLogger creates a new logger instance based on the provided configuration. It returns a SugaredLogger, which is a wrapper around zap's Logger that provides a more user-friendly API.
func SetConfig ¶
func SetConfig(c *Config)
SetConfig updates the logging configuration for the default logger. It automatically enables file logging if the application is in production mode. Must be called before DefaultLogger() to take effect.
func WithLogger ¶
WithLogger creates a new context with the provided logger attached to it. This is useful for passing the logger around in request handlers and other contexts.
Types ¶
type Config ¶
type Config struct { Encoding string // Log output format: "console" or "json" Level zapcore.Level // Default log level (e.g., Info, Debug, Error) Development bool // Whether the logger is in development mode LogToFile bool // Whether to log to a file (automatically enabled in production) LogDirectory string // Directory where log files will be stored Production bool // Whether the application is in production mode }
Config holds the configuration settings for the logger.