examples/

directory
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: MIT

README

Examples

Runnable demos showing common LogLayer wiring patterns. Each example is a standalone main package.

Example Demonstrates
http-server integrations/loghttp middleware: per-request logger derivation in an HTTP handler
multi-transport Fan-out: pretty in dev + structured to a file with per-transport level filtering
custom-transport Implementing the loglayer.Transport interface from scratch (renderer / "flatten" policy)
custom-transport-attribute Transport that forwards to an attribute-style backend (wrapper policy)
custom-plugin Writing a plugin from scratch: OnBeforeDataOut, OnMetadataCalled, and ShouldSend hooks
datadog-shipping Datadog Logs intake setup with tuned batching, error callback, and graceful Close
otel-end-to-end transports/otellog + plugins/oteltrace against a real OTel SDK with stdout exporters

Run any of them with:

go run ./examples/<name>

Each main.go is intentionally short (50-100 lines) so it doubles as a copy-paste starting point. None require a third-party service unless explicitly noted (the Datadog example degrades to a console transport when DD_API_KEY is not set).

The otel-end-to-end example lives in its own Go module because the OpenTelemetry transport and plugin are themselves split out (see AGENTS.md "When to Split a Transport into Its Own Module"). Because Go treats it as a separate module, you have to cd into it to run:

cd examples/otel-end-to-end
go run .

Directories

Path Synopsis
Implementing a custom Transport (renderer / "flatten" policy).
Implementing a custom Transport (renderer / "flatten" policy).
Implementing a custom Transport (attribute-forwarding / wrapper policy).
Implementing a custom Transport (attribute-forwarding / wrapper policy).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL