Skip to content

Conversation

@Dygear
Copy link
Contributor

@Dygear Dygear commented Jan 14, 2026

More testing is required for a few days before this is merged in, I want to make sure it works as intended before pulled.

Added a syslogFriendly config option, that by default is false. When set to true creates a trunk-recorder.log file that can be rotated with logrotate. Logrotate sends a SIGHUP signal that is handled by this change. Closes #833.

Implementation Summary

Changes Made:

  1. trunk-recorder/global_structs.h:39 - Added bool syslog_friendly field to the Config struct

  2. trunk-recorder/config.cc:

    • Added global log sink variable for SIGHUP handler access
    • Modified setup_file_log() to accept syslog_friendly parameter
    • When syslog_friendly is true, uses static filename trunk-recorder.log instead of timestamped %m-%d-%Y_%H%M_%2N.log
    • When syslog_friendly is true, disables automatic rotation (no rotation_size or time_based_rotation)
    • Added config reading for syslogFriendly option (defaults to false)
    • Added logging output to show the mode status
  3. trunk-recorder/monitor_systems.cc:

    • Added SIGHUP signal handler (rotate_log_signal)
    • Added flag rotate_log_flag to safely handle signal in main loop
    • Implemented log rotation logic that flushes and reopens the log file when SIGHUP is received
    • Logs rotation events for debugging

How to Use:

Add this to your config.json:

{
  "logFile": true,
  "logDir": "logs",
  "syslogFriendly": true,
  ...
}

Example logrotate Configuration:

Create /etc/logrotate.d/trunk-recorder:

/path/to/logs/trunk-recorder.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    postrotate
        killall -SIGHUP trunk-recorder
    endscript
}

Behavior:

  • Default (syslogFriendly: false): Uses timestamped log files with automatic rotation at 100MB or daily
  • Syslog-friendly mode (syslogFriendly: true):
    • Uses static filename trunk-recorder.log
    • No automatic rotation by Trunk-Recorder
    • Responds to SIGHUP signal for external rotation (logrotate)
    • Logs rotation events for monitoring

set to `true` creates a `trunk-recorder.log` file that can be rotated
with logrotate via logrotate sending a `SIGHUP` signal. Closes TrunkRecorder#833.
@robotastic
Copy link
Collaborator

This makes sense to me - can you add an entry to the Config doc: https://github.com/TrunkRecorder/trunk-recorder/blob/master/docs/CONFIGURE.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make logging logrotate friendly

2 participants