---
url: /logly.zig/examples/json-logging.md
description: >-
  Structured JSON logging with Logly.zig including context, trace IDs, and stack
  traces.
---

# JSON Logging

Structured output with bound context and error stack traces.

```zig
var config = logly.Config.default();
config.format = .json;
var logger = try logly.Logger.initWithConfig(allocator, config);
defer logger.deinit();

try logger.bind("environment", .{ .string = "production" });
try logger.info("Application started", @src());
```

Output:

```json
{
  "timestamp": "2026-10-07 05:57:02.419",
  "level": "INFO",
  "message": "Application started",
  "context": {
    "environment": "production"
  }
}
```
