Documentation ¶
Index ¶
- Constants
- func ApplicationLogWriteCloser(dir, name string, fallback io.Writer) io.WriteCloser
- func HandlerLogger(r *http.Request, handlerName string) *slog.Logger
- func NewAccessLogHandler(h http.Handler, logger *slog.Logger, o *AccessLogOptions) http.Handler
- func NewApplicationLoggerCloser(dir, name string, newHandler func(io.Writer) slog.Handler, fallback io.Writer) (l *slog.Logger, closeFunc func() error)
- func NewContextLoggerHandler(h http.Handler, l *slog.Logger) http.Handler
- func NewDailyReplaceableWriterConstructor(dir, name string) func(flag string) (f io.Writer, today string, err error)
- func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) slog.Handler
- func NewSlogContext(ctx context.Context, l *slog.Logger) context.Context
- func NewTextHandler(w io.Writer, opts *slog.HandlerOptions) slog.Handler
- func SlogFromContext(ctx context.Context) *slog.Logger
- type AccessLogOptions
- type Metrics
- type MetricsOptions
Constants ¶
const HandlerKey = "handler"
HandlerKey is a log key for the handler name added by HandlerLogger function.
Variables ¶
This section is empty.
Functions ¶
func ApplicationLogWriteCloser ¶
func ApplicationLogWriteCloser(dir, name string, fallback io.Writer) io.WriteCloser
ApplicationLogWriteCloser returns a writer which is a daily rotated file constructed using NewDailyReplaceableWriterConstructor.
func HandlerLogger ¶ added in v0.8.2
HandlerLogger provides a logger from HTTP request with attached name of the handler.
func NewAccessLogHandler ¶
NewHandler returns a handler that logs HTTP requests. It logs information about remote address, X-Forwarded-For or X-Real-Ip, HTTP method, request URI, HTTP protocol, HTTP response status, total bytes written to http.ResponseWriter, response duration, HTTP referrer and HTTP client user agent.
func NewApplicationLoggerCloser ¶ added in v0.8.3
func NewApplicationLoggerCloser(dir, name string, newHandler func(io.Writer) slog.Handler, fallback io.Writer) (l *slog.Logger, closeFunc func() error)
NewApplicationLoggerCloser construct a logger and returns a closer of its writer. It uses ApplicationLogWriteCloser with iostuff.NewDailyReplaceableWriterConstructor for log rotation.
func NewContextLoggerHandler ¶ added in v0.8.2
NewContextLoggerHandler injects logger into HTTP request Context. HandlerLogger function can be used to get the logger and attach a handler name.
func NewDailyReplaceableWriterConstructor ¶
func NewDailyReplaceableWriterConstructor(dir, name string) func(flag string) (f io.Writer, today string, err error)
NewDailyReplaceableWriterConstructor creates a writer constructor that can be used for daily rotated files for iostuff.NewReplaceableWriter. The files are named using pattern dir/2006/01/02/name.log where dir and name are passed arguments and the date parameters are year, month and day values of the current time.
func NewJSONHandler ¶ added in v0.8.3
NewJSONHandler calls slog.NewJSONHandler but returns the Logger interface to be used as an argument in NewApplicationLoggerCloser.
func NewSlogContext ¶ added in v0.8.9
NewSlogContext returns a context that contains the given Logger. Use FromContext to retrieve the Logger.
func NewTextHandler ¶ added in v0.8.3
NewTextHandler calls slog.NewTextHandler but returns the Logger interface to be used as an argument in NewApplicationLoggerCloser.
Types ¶
type AccessLogOptions ¶
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds Prometheus counters.
func NewMetrics ¶
func NewMetrics(options *MetricsOptions) (c *Metrics)
NewMetrics creates new Counter instance. Options value can be nil.
func (*Metrics) Metrics ¶
func (c *Metrics) Metrics() (cs []prometheus.Collector)
Metrics returns all Prometheus metrics that should be registered.