

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:
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:
production, staging, development)For our purposes, we'll log two fields that are almost always useful:
production, staging, development)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 ./linko
Run and submit the CLI tests from the root of the Linko repo.