example/

directory
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT

README

Examples

Run from the module root (github.com/vearne/zaplog).

Dir What it shows Command
basic InitLogger() defaults, SetLevel, Sync, Named go run ./example/basic
file WithFile + rotation; auto-create parent dirs go run ./example/file
teeJSON File + stdout tee, JSON encoder (container-friendly) go run ./example/teeJSON
noContext Non-context logs + Prometheus log_total metrics go run ./example/noContext
withContext InfoContext + WithTraceID / WithAutoEvents go run ./example/withContext

Quick start

# zero-config: info → stdout
go run ./example/basic

# file only
go run ./example/file

# JSON to stdout and file
go run ./example/teeJSON

Init cheat sheet

zlog.InitLogger() // level=info, stdout

zlog.InitLogger(zlog.WithFile("/var/log/app.log"), zlog.WithLevel("debug"))

zlog.InitLogger(
    zlog.WithFile("/var/log/app.log"),
    zlog.WithStdout(),
    zlog.WithJSON(),
)

zlog.SetLevel("debug")
defer zlog.Sync()

Output rule: if you pass no WithFile / WithStdout / WithStderr, stdout is used. As soon as any of those is set, only the sinks you listed are enabled.

Directories

Path Synopsis
Basic usage: zero-config InitLogger (default level=info, output=stdout), runtime SetLevel, and Sync on exit.
Basic usage: zero-config InitLogger (default level=info, output=stdout), runtime SetLevel, and Sync on exit.
File-only logging with rotation options.
File-only logging with rotation options.
Non-context logging + OpenTelemetry metrics (log_total counter).
Non-context logging + OpenTelemetry metrics (log_total counter).
Container-style setup: JSON logs to stdout, optionally also to a file (tee).
Container-style setup: JSON logs to stdout, optionally also to a file (tee).
Context-aware logging with trace_id injection and auto span events.
Context-aware logging with trace_id injection and auto span events.

Jump to

Keyboard shortcuts

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