Documentation
¶
Overview ¶
Package vokerslog provides a slog.Handler tuned for AWS Lambda functions.
It auto-configures log format (JSON or text) and level from Lambda's advanced logging environment variables, and enriches every record with Lambda metadata (function name, version, and the request ID from the invocation context). Options override the environment values.
See https://docs.aws.amazon.com/lambda/latest/dg/monitoring-logs.html
Usage:
logger := slog.New(vokerslog.NewHandler(os.Stderr)) slog.SetDefault(logger) voker.Start(handler, voker.WithLogger(logger))
Index ¶
Constants ¶
const TypeKey = "type"
TypeKey is the attribute key that overrides a record's "type" field. A top-level (not nested in a group) string attribute with this key sets the type for that record instead of being emitted as an ordinary attribute. It may be set per call or, via WithAttrs, for every record from a logger:
requests := slog.New(handler).With(vokerslog.TypeKey, "app.request")
A per-call value takes precedence over one set via WithAttrs. See WithType.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements slog.Handler and writes structured log records to an io.Writer. Use NewHandler to create one.
func NewHandler ¶
NewHandler returns a Handler that writes to w.
By default it reads AWS_LAMBDA_LOG_LEVEL (TRACE, DEBUG, INFO, WARN, ERROR, FATAL) and AWS_LAMBDA_LOG_FORMAT (json, text) from the environment. Any provided options take precedence over environment values.
type Option ¶
type Option func(*Handler)
Option configures a Handler. Pass options to NewHandler.
func WithLevel ¶
WithLevel sets the minimum log level. Messages below this level are dropped. Defaults to the value of AWS_LAMBDA_LOG_LEVEL, or INFO if unset.
func WithSource ¶
func WithSource() Option
WithSource adds caller information (function, file, line) to each log record.
func WithType ¶
WithType sets the "type" field included in every log record. Defaults to "app.log".
The "type" + "record" envelope mirrors the shape of AWS Lambda Telemetry API events, so "type" is best used as a low-cardinality category for filtering and routing logs (for example in CloudWatch Logs Insights), not for per-request data. AWS reserves the values "function", "extension", and "platform.*"; a dotted "app.<category>" namespace (such as "app.log", "app.request", or "app.audit") avoids collisions and matches AWS's style.
An individual record can override this default with a top-level string attribute named TypeKey; setting it to "" omits the field for that record.
func WithoutTime ¶
func WithoutTime() Option
WithoutTime omits the timestamp from log output. Useful for testing or when CloudWatch already provides timestamps.