---
url: /logly.zig/examples/sink-formats.md
description: >-
  Example of configuring different output formats per sink in Logly.zig. Plain
  text console, raw JSON for ingestion, and pretty JSON for debugging
  simultaneously.
---

# Sink Formats

This example demonstrates how to configure different output formats for different sinks. You can have one sink writing plain text to the console, another writing raw JSON to a file for ingestion, and a third writing pretty-printed JSON for debugging.

## Code Example

```zig
const std = @import("std");
const logly = @import("logly");

pub fn main() !void {
    var gpa = std.heap.DebugAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    // Enable colors on Windows
     _ = logly.Terminal.enableAnsiColors();

    const logger = try logly.Logger.init(allocator);
    defer logger.deinit();

    // Disable auto console sink to configure everything manually
    var config = logly.Config.default();
    config.autoSink = false;

    // Enable filename and line number display (Clickable in VS Code)
    config.showFilename = true;
    config.showLineno = true;

    // Custom date format (YYYY-MM-DD HH:MM:SS.mmm)
    config.timeFormat = "default";

    logger.configure(config);

    // 1. Standard Console Sink (with colors) - using add() alias
     _ = try logger.add(.{});

    // 2. Plain Text File Sink (no colors)
     _ = try logger.add(.{
        .path = "logs/plain.txt",
        .color = false,
    });

    // 3. JSON File Sink
     _ = try logger.add(.{
        .path = "logs/data.json",
        .format = .json,
    });

    // 4. Pretty JSON File Sink
     _ = try logger.add(.{
        .path = "logs/pretty.json",
        .format = .json,
        .prettyJson = true,
    });

    try logger.info("This message goes to all sinks in different formats!", @src());
    try logger.err("Error at specific line (try clicking the filename in console)", @src());
}
```

## Expected Output

**Console**:

```text
[INFO] This message goes to all sinks in different formats! (src/main.zig:52)
[ERROR] Error at specific line (try clicking the filename in console) (src/main.zig:53)
```

**logs/data.json**:

```json
{
  "level": "INFO",
  "message": "This message goes to all sinks in different formats!",
  "timestamp": 1717286400000,
  "filename": "src/main.zig",
  "line": 52
}
```

**logs/pretty.json**:

```json
{
  "level": "INFO",
  "message": "This message goes to all sinks in different formats!",
  "timestamp": 1717286400000,
  "filename": "src/main.zig",
  "line": 52
}
```
