logging

package
v0.0.0-...-7a2aee4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 9 Imported by: 0

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 SetLevel

func SetLevel(l zapcore.Level)

SetLevel updates the logging level for the default logger.

func WithLogger

func WithLogger(ctx context.Context, logger *zap.SugaredLogger) context.Context

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL