Skip to content

Feature Request: Add file-based LogsReceiver with rotation and compression support #4262

@korniltsev

Description

@korniltsev

Summary

Currently, the logging block's write_to parameter only supports Loki-based LogsReceiver components (like loki.write, loki.relabel, etc.). There's no built-in way to write Alloy's internal logs directly to files with log rotation and compression capabilities.

Problem

Users who want to:

  1. Write Alloy's internal logs to local files (not just stderr)
  2. Implement log rotation to manage disk usage
  3. Compress rotated logs to save space
  4. Avoid the complexity of setting up a full Loki instance just for internal logging

Currently have limited options and must rely on external tools or complex setups.

Proposed Solution

Add a new component (e.g., local.file_write) that implements the LogsReceiver interface and provides:

  • File-based log output with configurable path
  • Built-in log rotation based on size, age, or both
  • Compression of rotated files
  • Configurable retention policies

This could leverage existing libraries like lumberjack which provides these features out of the box.

Example Usage

local.file_write "internal_logs" {
  filename     = "/var/log/alloy/alloy.log"
  max_size     = 100  // MB
  max_backups  = 3
  max_age      = 28   // days
  compress     = true
}

logging {
  level    = "info"
  format   = "json"
  write_to = [local.file_write.internal_logs.receiver]
}

Benefits

  • Simplified log management for users who prefer file-based logging
  • Built-in rotation and compression without external dependencies
  • Consistent with Alloy's component-based architecture
  • Reduces operational complexity for users not using Loki

Alternative Workarounds

Currently, users must:

  • Use system-level log rotation tools with stderr redirection
  • Set up a local Loki instance just for internal logs
  • Implement custom log forwarding solutions

A built-in file-based LogsReceiver would eliminate these complexities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestproposalA proposal for new functionality.

    Type

    No type

    Projects

    Status

    Incoming

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions