logger

package
v0.0.0-...-77d485b Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package logger provides a simplified interface for creating and configuring loggers using the Uber's zap logging library. It includes functions to create both production and development loggers with appropriate configurations.

The production logger is optimized for performance and is suitable for use in a production environment. The development logger, on the other hand, provides more verbose output and is intended for use during the development process.

Additionally, provides a simple and convenient wrapper around the zap logging library. It offers structured logging capabilities across various log levels, including fatal, error, warning, info, and debug.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(message string, fields ...zap.Field)

Debug logs a message at the debug level including any additional fields provided. This level is used for detailed informational messages that are useful for debugging an application. These messages are typically voluminous and are not required in a production environment.

Parameters:

message - The log message to be written.
fields  - Optional zap fields for additional structured context.

func Error

func Error(message string, err error, fields ...zap.Field)

Error logs a message at the error level including any additional fields provided. This level is used for logging errors that have occurred during execution. These errors might require attention but do not necessarily indicate an immediate failure of the entire application.

Parameters:

message - The log message to be written.
err     - The error object associated with this log message.
fields  - Optional zap fields for additional structured context.

func Fatal

func Fatal(message string, err error, fields ...zap.Field)

Fatal logs a message at the fatal level including any additional fields provided. The logger then calls os.Exit(1), terminating the program. Use this level for errors that should not occur during normal operation and indicate a severe problem that requires immediate attention.

Parameters:

message - The log message to be written.
err     - The error object associated with this log message.
fields  - Optional zap fields for additional structured context.

func GetDevelopmentLogger

func GetDevelopmentLogger(level zap.AtomicLevel) (*zap.Logger, error)

GetDevelopmentLogger creates and returns a new zap.Logger configured for development use. The development logger is more verbose and is intended for use during development. It uses a console encoder with colored level output and logs at the specified log level.

Parameters:

level - The minimum logging level at which logs should be written,
        e.g., zapcore.DebugLevel, zapcore.InfoLevel.

Returns:

*zap.Logger - The configured zap.Logger for development use.
error       - An error if the logger could not be created.

func GetLogger

func GetLogger(env string, level string) (*zap.Logger, error)

func GetProductionLogger

func GetProductionLogger(level zap.AtomicLevel) (*zap.Logger, error)

GetProductionLogger creates and returns a new zap.Logger configured for production use. The production logger is optimized for performance. It uses a JSON encoder, logs to standard error, and writes at InfoLevel and above.

Returns:

*zap.Logger - The configured zap.Logger for production use.
error       - An error if the logger could not be created.

func Info

func Info(message string, fields ...zap.Field)

Info logs a message at the info level including any additional fields provided. Use this level for informational messages that highlight the progress of the application under normal circumstances.

Parameters:

message - The log message to be written.
fields  - Optional zap fields for additional structured context.

func Warn

func Warn(message string, fields ...zap.Field)

Warn logs a message at the warning level including any additional fields provided. This level is used for potentially harmful situations that warrant attention but do not represent immediate errors.

Parameters:

message - The log message to be written.
fields  - Optional zap fields for additional structured context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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