Logging
Use the App logger to record outcomes such as a completed operation or an unavailable dependency. Access logs already record requests and their HTTP status. Add application logs when the handler or service can explain what happened.
Write a Request-Scoped Log
In the App from Your First Route, add the logger to the users controller. Import your module's internal/logger package in internal/users/controller.go. Update the controller and constructor so Wire can inject the App's logger.
// Controller translates user lookups into HTTP responses.
type Controller struct {
service *Service
logger *logger.AppLogger
}
// NewController receives the service and logger from the App.
func NewController(service *Service, appLogger *logger.AppLogger) *Controller {
return &Controller{service: service, logger: appLogger}
}In Show, add this call after the lookup succeeds and before the JSON response. Binding the request context lets the logger include the correlation fields already available for this request.
c.logger.WithContext(ctx.Context()).Info().
Str("route", "/api/v1/users/:id").
Msg("User lookup completed")Wait for forj dev to rebuild, then request the route from a second terminal.
curl -fsS http://localhost:3000/api/v1/users/42Look for User lookup completed in the App terminal. Set APP_LOG_FORMAT=json to expose route as a named field. Use Tracing to follow work across components.
Good Default Logs
Good default-visible logs include:
- HTTP server start and stop
- queue worker start and stop
- scheduler start and stop
- route count summary
- clear degraded-runtime warnings
- dev ready markers
These lines identify the process and its lifecycle. Include the App identity so events from multiple Apps remain distinguishable. Collect standard output and standard error through your process supervisor or hosting platform.
Startup and Shutdown Investigation
Start with the App process's captured standard output and standard error. The command depends on how the App is deployed:
| Environment | Recent process output |
|---|---|
| Kubernetes | kubectl logs deployment/example --tail=100 |
| Docker | docker logs --tail 100 example |
| systemd | journalctl -u example.service -n 100 --no-pager |
Use the equivalent log view in your process supervisor or hosting platform. When running the binary directly, inspect its terminal output.
Expected result: startup identifies the HTTP bind address and route count, while workers and schedulers identify their lifecycle transitions. A normal shutdown includes a shutdown marker; workers can also report active jobs while they wait within their configured budget.
If a combined Runtime exits, look for the first Runtime error rather than assuming all sibling processes failed independently. The Runtime host cancels sibling Runtimes after the first non-cancellation failure.
Debug-Level Chatter
Keep detailed primitive chatter at debug level or behind explicit controls.
Examples:
- per-hook lifecycle detail
- repeated backend connection detail
- low-level driver start and stop noise
- verbose request internals
Route Logging
Boot should not print the full route table.
From the Project root, run forj route:list for the full route table or forj admin route:list for the staff operations App.
HTTP Access Logs
Generated HTTP runtimes enable access logs by default. Control them with:
HTTP_ACCESS_LOG_ENABLED=trueEach request event retains named fields for URI, method, status, latency, and client IP. Logger configuration carries App identity, while request context can add runtime source and inspect identity.
Console output uses a compact value-oriented line with status-aware color. JSON output and registered log sinks retain the structured field names, so machine processing does not depend on console formatting.
Disable access logs for a runtime where request volume would hide higher-signal events, then rely on metrics and inspects for the intended visibility.
Keep access logs enabled during a new deployment until the request path, status, and latency are understood. If you disable them for steady-state volume, retain an explicit route-level metric and a safe Inspect sampling policy; otherwise a 5xx increase has no request-level path back to an operator.
Timestamps
Set APP_LOG_TIME=true to show timestamps. Logs follow the App timezone configured through APP_TZ.
Safe Fields and Correlation
Use fields such as App identity, runtime, route pattern, status, and latency. A contextual log carries trace_id and span_id when an OpenTelemetry span is active. It carries inspect_id when Lighthouse capture attaches an Inspect to the request. See Tracing for following those IDs.
Never log authorization headers, cookies, credentials, raw queue payloads, or unredacted request bodies by default. Local HTTP error-response capture is intentionally local-environment behavior; do not rely on it as a production payload-dump mechanism.
Failure Modes
| Symptom | Likely meaning | Operator action |
|---|---|---|
| Repeated low-level connection errors | A required dependency may be unreachable, or an optional one may be degraded. | Find the one high-level readiness/degraded warning and repair the dependency; do not alert on every reconnect line. |
| Missing App identity in a multi-App Project | Logs cannot be attributed to the owning App. | Correct logger wiring before using a shared sink for deployment decisions. |
| No request evidence during an incident | Access logs were disabled or not collected. | Use metrics and Inspects immediately; restore a safe access-log policy after the incident. |
| Secret appears in output | A log field or payload capture is unsafe. | Restrict access, rotate the secret, and remove/redact the emitting field. |
Production Checklist
- Service output is collected and retained by the platform log system.
- Startup, shutdown, readiness failure, and degraded-resource lines are searchable by App and Runtime.
- Access-log volume is an intentional policy, not accidental suppression.
- Secret and payload redaction has been reviewed for application-owned logs.