Documentation ¶
Index ¶
- Constants
- Variables
- func Error(err error) slog.Attr
- func FromContext(ctx context.Context) *slog.Logger
- func Label(attr ...any) slog.Attr
- func Name(value string) slog.Attr
- func NewHandler(w io.Writer, opts *HandlerOptions) slog.Handler
- func NewLogger(w io.Writer, options *HandlerOptions) *slog.Logger
- func OperationContinue(id, producer string) slog.Attr
- func OperationEnd(id, producer string) slog.Attr
- func OperationStart(id, producer string) slog.Attr
- func Request(r *http.Request, opts ...RequestOption) slog.Attr
- func Response(r *http.Response, opts ...RequestOption) slog.Attr
- func ResponseWriter(r http.ResponseWriter, opts ...RequestOption) slog.Attr
- func WithContext(ctx context.Context, logger *slog.Logger) context.Context
- type ContextKey
- type Entry
- type Handler
- type HandlerOptions
- type LevelVar
- type RequestOption
- type RequestOptionFunc
Constants ¶
const ( NameKey = "name" ErrorKey = "error" LabelKey = "labels" RequestKey = "request" ResponseKey = "response" OperationKey = "operation" )
Variables ¶
var LoggerKey = &ContextKey{ name: reflect.TypeOf(ContextKey{}).PkgPath(), }
LoggerKey represents the context key of the logger.
Functions ¶
func FromContext ¶
FromContext returns the logger from a given context.
func Label ¶
Label returns an Attr for a Group Label. The caller must not subsequently mutate the argument slice.
Use Label to collect several Attrs under a labels key on a log line.
func Name ¶
Name returns an Attr for a log name. The caller must not subsequently mutate the argument slice.
Use Label to collect several Attrs under a name key on a log line.
func NewHandler ¶
func NewHandler(w io.Writer, opts *HandlerOptions) slog.Handler
NewHandler creates a slog.Handler that writes tinted logs to w, using the default options.
func NewLogger ¶
func NewLogger(w io.Writer, options *HandlerOptions) *slog.Logger
NewLogger crates a new logger instance.
func OperationContinue ¶
OperationContinue is a function for logging `Operation`. It should be called for any non-start/end operation log.
func OperationEnd ¶
OperationEnd is a function for logging `Operation`. It should be called for the last operation log.
func OperationStart ¶
OperationStart is a function for logging `Operation`. It should be called for the first operation log.
func Request ¶
func Request(r *http.Request, opts ...RequestOption) slog.Attr
Request returns an Attr for a http.Request. The caller must not subsequently mutate the argument slice.
Use Request to collect several Attrs under a HttpRequest key on a log line.
func Response ¶
func Response(r *http.Response, opts ...RequestOption) slog.Attr
Respone returns an Attr for a http.Respone. The caller must not subsequently mutate the argument slice.
Use Response to collect several Attrs under a HttpRequest key on a log line.
func ResponseWriter ¶
func ResponseWriter(r http.ResponseWriter, opts ...RequestOption) slog.Attr
ResponseWriter returns an Attr for a http.ResponseWriter. The caller must not subsequently mutate the argument slice.
Use Response to collect several Attrs under a HttpRequest key on a log line.
Types ¶
type ContextKey ¶
type ContextKey struct {
// contains filtered or unexported fields
}
ContextKey represents a context key.
func (*ContextKey) String ¶
func (k *ContextKey) String() string
String returns the context key as a string.
type Entry ¶
An individual entry in a log.
func (*Entry) GetJsonPayload ¶
GetJsonPayload returns the log entry payload, represented as a structure that is expressed as a JSON object.
func (*Entry) GetPayload ¶
func (x *Entry) GetPayload() interface{}
GetPayload returns the underlying payload
func (*Entry) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements a slog.Handler.
type HandlerOptions ¶
type HandlerOptions struct { // ProjectID is Google Cloud Project ID // If you want to use trace_id, you should set this or set GOOGLE_CLOUD_PROJECT environment. // Cloud Shell and App Engine set this environment variable to the project ID, so use it if present. ProjectID string // When AddIndent is true, the handler adds an ident to the JSON output. AddIndent bool // When AddSource is true, the handler adds a ("source", "file:line") // attribute to the output indicating the source code position of the log // statement. AddSource is false by default to skip the cost of computing // this information. AddSource bool // Level reports the minimum record level that will be logged. // The handler discards records with lower levels. // If Level is nil, the handler assumes LevelInfo. // The handler calls Level.Level for each record processed; // to adjust the minimum level dynamically, use a LevelVar. Level slog.Leveler }
HandlerOptions for a slog.Handler that writes tinted logs. A zero HandlerOptions consists entirely of default values.
type LevelVar ¶
type LevelVar string
StringLevel represents a slog.Leveler for string
func (*LevelVar) MarshalText ¶
MarshalText implements encoding.TextMarshaler by calling [Level.MarshalText].
func (*LevelVar) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler by calling [Level.UnmarshalText].
type RequestOption ¶
type RequestOption interface {
Apply(*ltype.HttpRequest)
}
RequestOption represents a request option
func WithLatency ¶
func WithLatency(v time.Duration) RequestOption
WithLatency sets the latency to a given request.
type RequestOptionFunc ¶
type RequestOptionFunc func(*ltype.HttpRequest)
RequestOptionFunc represents a request option function.
func (RequestOptionFunc) Apply ¶
func (fn RequestOptionFunc) Apply(r *ltype.HttpRequest)
Apply the option.