sync from project
This commit is contained in:
@ -75,6 +75,10 @@ func (log Log) WrapHandler(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
// Logger retrieves the slog.Logger from the request context.
|
||||
// If the logger is not found in the context (e.g., the httplog middleware is not used),
|
||||
// it creates and returns a new logger with basic request information.
|
||||
// Using the httplog middleware is recommended to ensure the configured logger is available.
|
||||
func Logger(r *http.Request) *slog.Logger {
|
||||
if logger, ok := r.Context().Value(loggerKey).(*slog.Logger); ok {
|
||||
return logger.With("time", time.Now())
|
||||
|
Reference in New Issue
Block a user