Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(ctx context.Context, msg string)
- func Debugf(ctx context.Context, format string, v ...any)
- func Error(ctx context.Context, err error, msg string)
- func Errorf(ctx context.Context, err error, format string, v ...any)
- func Fatal(ctx context.Context, err error, msg string)
- func Fatalf(ctx context.Context, err error, format string, v ...any)
- func Info(ctx context.Context, msg string)
- func Infof(ctx context.Context, format string, v ...any)
- func InitLogger(c Config) error
- func Panic(ctx context.Context, err error, msg string)
- func Panicf(ctx context.Context, err error, format string, v ...any)
- func Request(ctx context.Context, r *http.Request, body []byte)
- func Response(ctx context.Context, r *http.Request, statusCode int, ...)
- func Warn(ctx context.Context, msg string)
- func Warnf(ctx context.Context, format string, v ...any)
- type Config
Constants ¶
View Source
const ( Stdout destinationType = "stdout" File destinationType = "file" )
Destination types for logging output.
View Source
const ( DebugLevel level = "debug" InfoLevel level = "info" WarnLevel level = "warn" ErrorLevel level = "error" FatalLevel level = "fatal" PanicLevel level = "panic" )
Log levels define the severity of log messages.
Variables ¶
View Source
var ( ErrInvalidLogLevel = errors.New("invalid log level") ErrLogDestinationNil = errors.New("log Destinations cant be empty") ErrMissingFilePath = errors.New("file path missing in destination config for file logging") )
Logger instance and configuration.
Functions ¶
func Fatalf ¶
Fatalf logs a formatted fatal-level message along with an error object and exits the application.
func InitLogger ¶
InitLogger initializes the logger with the given configuration. It ensures that the logger is initialized only once using sync.Once.
func Request ¶
Request logs details of an incoming HTTP request, including method, URL, body, and remote address.
func Response ¶
Response logs details of an outgoing HTTP response, including method, URL, status code, and response time.
Types ¶
type Config ¶
type Config struct {
Level level `yaml:"level"`
Destinations []destination `yaml:"destinations"`
ContextKeys []model.ContextKey `yaml:"contextKeys"`
}
Config represents the configuration for logging.
Click to show internal directories.
Click to hide internal directories.