

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Logging Context
incomplete
2: Build Information
incomplete
3: Instance Context
incomplete
4: Request Context
incomplete
5: User Context
incomplete
6: HTTP Error Responses
incomplete
7: Inter-Process Context
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Different runtime context matters depending on how your app runs. For desktop or mobile apps, useful fields often include:
Host operating system
Time zone
Shared library versions
For backend services this is usually simpler, but scale still matters. Thousands of pods across regions need more context than one app on one EC2 instance.
All of this is probably overkill for most backends, but it's worth considering:
Runtime environment name (e.g. production, staging, development)
The server's hostname
The server's IP address
Cloud region
Node name or IP (for containerized services)
Docker container name or Kubernetes pod name
Host operating system and kernel version
Host/server time zone (particularly if you deploy across geographic regions)
For our purposes, we'll log two fields that are almost always useful:
Runtime environment name (e.g. production, staging, development)
Server hostname/domain (e.g. jons-macbook (local), c7a9d8b32c4a (container), or ip-172-31-22-45 (cloud server))
env := os.Getenv("ENV")
hostname, _ := os.Hostname()
logger = logger.With(
slog.String("env", env),
slog.String("hostname", hostname),
)Include runtime instance metadata in every log.
Build your app with -ldflags and run it with ENV and LINKO_LOG_FILE set:
go build \
-ldflags "-X boot.dev/linko/internal/build.GitSHA=$(git rev-parse HEAD) -X boot.dev/linko/internal/build.BuildTime=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" \
-o linko &&
LINKO_LOG_FILE=linko.access.log ENV=development ./linkoRun and submit the CLI tests from the root of the Linko repo.