Documentation
¶
Index ¶
- Constants
- func InitSubModule()
- func NewErrReport(err error, skipStacktrace bool) *errReport
- func NewJsonCodec(skipStacktrace bool) errors.Codec
- func NewTelemetryHandler(out io.Writer, level slog.Leveler) slog.Handler
- func RegisterContextFields(hook ContextFieldsFn)
- func SetResourceFields(fields map[string]string)
- func WithHttpFields(ctx context.Context, fields HttpFields) context.Context
- type Attr
- type ContextFieldsFn
- type HttpFields
- type Level
- type LoggerService
Constants ¶
const ( FieldIdempotencyId = "idempotency_id" FieldTenantId = "tenant_id" FieldOrgId = "org_id" FieldServiceName = "service.name" )
Variables ¶
This section is empty.
Functions ¶
func InitSubModule ¶
func InitSubModule()
func NewErrReport ¶
func NewJsonCodec ¶
NewJsonCodec encodes error data as JSON documents. If `pretty` is set to `true` the output will be indented for readability.
func RegisterContextFields ¶
func RegisterContextFields(hook ContextFieldsFn)
func SetResourceFields ¶
SetResourceFields is called by telemetry once its resource is built; until then the resource fields are null.
func WithHttpFields ¶
func WithHttpFields(ctx context.Context, fields HttpFields) context.Context
Types ¶
type ContextFieldsFn ¶
ContextFieldsFn reads operation fields (idempotency_id, tenant_id, org_id) from ctx. It exists because the packages that own those values import logging, so logging cannot import them.
type HttpFields ¶
HttpFields are the access-log fields. They reach the top level of a record only through WithHttpFields, never through caller data.
func HttpFieldsOf ¶
func HttpFieldsOf(ctx context.Context) (HttpFields, bool)
type LoggerService ¶
type LoggerService interface {
InnerLogger() any
Clone() LoggerService
Level() Level
SetLevel(lvl Level)
Debug(ctx context.Context, message string, data Attr)
Debugf(ctx context.Context, format string, args ...any)
Info(ctx context.Context, message string, data Attr)
Infof(ctx context.Context, format string, args ...any)
Warn(ctx context.Context, message string, data Attr)
Warnf(ctx context.Context, format string, args ...any)
Error(ctx context.Context, message string, err error)
Errorf(ctx context.Context, format string, args ...any)
}
LoggerService takes ctx on every write so each record carries the span, idempotency id, tenant and org active at that point, not those of the place the logger was obtained. Code with no operation (boot, shutdown, CLI) passes context.Background(): the fields are null.
func Logger ¶
func Logger() LoggerService
func NewLogger ¶
func NewLogger(levels ...Level) LoggerService
func NewLoggerTo ¶
func NewLoggerTo(out io.Writer, levels ...Level) LoggerService
NewLoggerTo writes to out instead of stdout; tests read the JSON lines back from it.