Search code examples
c++boostboost-log

Boost.Log: custom action on rotation of files


Our application uses Boost.Log (1.63) and it works quite well. We are using the rotation/archiving feature and file names with incremeting numbers.

Now we would like to watch the log files for Errors.

The monitoring software our organization uses needs absolute file names, so file names with an incrementing number suffix won't work.

As far as I understand Boost.Log cannot be configured that the actual log file always has a fixed file name and only the archived files have suffixes. Is this correct?

The other idea we had was to create an symlink to the actual log file on every file rotation. Is there a possibility to add an custom action to each rotation event?


Solution

  • As far as I understand Boost.Log cannot be configured that the actual log file always has a fixed file name and only the archived files have suffixes. Is this correct?

    Yes, the file name is generated by the sink backend when the file is first opened for writing. When the file is rotated, that file name is preserved.

    Is there a possibility to add an custom action to each rotation event?

    There are file open and close handlers. These callbacks receive a file stream, not the file name. But you can obtain the current file name from the sink backend by calling get_current_file_name.

    As an idea, you may want to create a custom sink that will monitor errors in logs and add it to the core just like the file sink. If you set the same filter as the one in the file sink, only with a severity check that only passes error log records, that monitor sink will receive errors that are also logged by the file sink. Guidelines for creating custom sinks are described here.