logger

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 7 Imported by: 3

README ΒΆ

πŸ“¦ Package logger

Source Path: pkg/logger

🏷️ Variables

var once sync.Once

🧩 Types

Logger
type Logger struct {
	Log *zap.Logger
}
Methods
Debug

Debug logs a message at the Debug level. It accepts a message string and optional zap fields to include additional context in the log entry.

func (l *Logger) Debug(message string, fields ...zap.Field)
Error

Error logs a message at the Error level. It accepts a message string and optional zap fields to include additional context in the log entry.

func (l *Logger) Error(message string, fields ...zap.Field)
Fatal

Fatal logs a message at the Fatal level. It accepts a message string and optional zap fields to include additional context in the log entry. The function will log the message and then terminate the application.

func (l *Logger) Fatal(message string, fields ...zap.Field)
Info

Info logs a message at the Info level. It accepts a message string and optional zap fields to include additional context in the log entry.

func (l *Logger) Info(message string, fields ...zap.Field)
LoggerInterface
type LoggerInterface interface {
	Info func(message string, fields ...zap.Field)
	Fatal func(message string, fields ...zap.Field)
	Debug func(message string, fields ...zap.Field)
	Error func(message string, fields ...zap.Field)
}

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Logger ΒΆ

type Logger struct {
	Log *zap.Logger
}

func (*Logger) Debug ΒΆ

func (l *Logger) Debug(message string, fields ...zap.Field)

Debug logs a message at the Debug level. It accepts a message string and optional zap fields to include additional context in the log entry.

func (*Logger) Error ΒΆ

func (l *Logger) Error(message string, fields ...zap.Field)

Error logs a message at the Error level. It accepts a message string and optional zap fields to include additional context in the log entry.

func (*Logger) Fatal ΒΆ

func (l *Logger) Fatal(message string, fields ...zap.Field)

Fatal logs a message at the Fatal level. It accepts a message string and optional zap fields to include additional context in the log entry. The function will log the message and then terminate the application.

func (*Logger) Info ΒΆ

func (l *Logger) Info(message string, fields ...zap.Field)

Info logs a message at the Info level. It accepts a message string and optional zap fields to include additional context in the log entry.

type LoggerInterface ΒΆ

type LoggerInterface interface {
	Info(message string, fields ...zap.Field)
	Fatal(message string, fields ...zap.Field)
	Debug(message string, fields ...zap.Field)
	Error(message string, fields ...zap.Field)
}

func NewLogger ΒΆ

func NewLogger(service string) (LoggerInterface, error)

NewLogger returns a singleton instance of LoggerInterface with a logger that writes JSON-formatted log messages to both stdout and a log file. The log file name is determined by the service parameter. If the service parameter is empty, the log file name will be "app.log". The logger will be configured to write logs in the following locations:

  • stdout, if the APP_ENV environment variable is not set
  • /var/log/app/<service>.log, if the APP_ENV environment variable is set to "docker", "production", or "kubernetes"
  • ./logs/<service>.log, otherwise

The logger will fallback to stdout only if it fails to create the log directory or open the log file.

The logger will use the DebugLevel by default.

Directories ΒΆ

Path Synopsis
Package mock_logger is a generated GoMock package.
Package mock_logger is a generated GoMock package.

Jump to

Keyboard shortcuts

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