Documentation
ΒΆ
Index ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Logger ΒΆ
func (*Logger) 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 (*Logger) 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.
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.