Menu

File Rotation

abcdef
2012-10-02
2013-06-03
  • abcdef

    abcdef - 2012-10-02

    We're currently trying to log to a file without a date/time stamped filename and then rotate it once a day to have a date/time stamped name.
    We're almost getting it to work using Target, Filename, ScanForFiles, Append and AutoFlush.

    This kind of functionality can be implemented using logrotate:

    http://linux.die.net/man/8/logrotate

    Boost log does not appear to have quite the same rotation abilities.
    Is there a way to do this easily using Boost Log or would you advise we use logrotate ?

     
  • Andrey Semashev

    Andrey Semashev - 2012-10-02

    Boost.Log only implements functionality that is required from the logging application to rotate logs (file naming and simple collecting). It doesn't implement any collateral advanced features, such as log compression or mailing. This kind of things should be done by external utilities, be that logrotate or other tools. In my mind, the most flexible solution would be a combination of Boost.Log and external tools for further log processing.

    If you choose to employ logrotate to collect the logs and find any problems, please let me know.

     
  • abcdef

    abcdef - 2012-10-02

    For now we're just after the aforementioned rename from a non-date named file rotated to a date named file.
    Is this part of the standard functionality of the planned boost log v2 or is it already there ?

     
  • Andrey Semashev

    Andrey Semashev - 2012-10-02

    No, the log file should contain date/time in its name from the start. More details are available here. I think, v2 won't have this feature but it may be added later.

     
  • abcdef

    abcdef - 2012-10-03

    I've found 2 bugs when trying to use rotation and appending in conjunction with one another:
    1) The file does not rotate unless atleast 2 messages have been logged.
    2) Rotation does not truncate the output file when in append mode.

     
  • abcdef

    abcdef - 2012-10-03

    The following is a possible solution to the aforementioned problems:\newline
    \newline
    diff -r boost-log_revision_728/libs/log/src/text_file_backend.cpp boost-log_revision_728NEW/libs/log/src/text_file_backend.cpp\newline
    1172a1173\newline
    > std::ios_base::openmode fileOpenMode = m_pImpl->m_FileOpenMode;\newline
    1177d1177\newline
    <             m_pImpl->m_File.is_open() &&\newline
    1181c1181,1182\newline
    <             )\newline
    --\newline
    >             ) &&\newline
    >             m_pImpl->m_File.is_open()\newline
    1186a1188\newline
    >         fileOpenMode = std::ios_base::trunc | std::ios_base::out;\newline
    1194c1196\newline
    <         m_pImpl->m_File.open(m_pImpl->m_FileName, m_pImpl->m_FileOpenMode);\newline
    --\newline
    >         m_pImpl->m_File.open(m_pImpl->m_FileName, fileOpenMode);\newline

     

Log in to post a comment.