Menu

Basic logfile rotation to history directory.

Help
Rob Kramer
2014-02-06
2014-02-07
  • Rob Kramer

    Rob Kramer - 2014-02-06

    Hi,

    I'm trying to switch from log4cxx to boost.log. My applications normally log to (for example) /xxx/log/user.log. At midnight, log4cxx will move the user.log to /xxx/log/history/user-20140205.log. If the application restarts, it will just append to user.log.

    Is this supported in boost.log?

    Would it make more sense to do this using logrotate instead? I've never used that; I'm not sure how that would work if the logfile is kept open by boost.log.

    Cheers!

    Rob
    
     
  • Andrey Semashev

    Andrey Semashev - 2014-02-06

    Boost.Log supports log rotation, see here. But the file name is generated when the sink is created, so the current log file will be not user.log but user-<today>.log. Note that having date/time in the file name can interfere with appending to the previous file when restarting since the generated file name may be different. But if you rotate at midnight and the file name only contains date, this shouldn't be a problem.

    You can use logrotate, and this might be the preferable solution since people are usually more familiar with it. All you need to do with Boost.Log then is to manually invoke file rotation upon some signal (such as SIGHUP) so that the log file is reopened when logrotate kicks in.

     
  • Rob Kramer

    Rob Kramer - 2014-02-07

    I've been using the file sink, but got confused with how rotation is supposed to work. It seems the application logfile was always being written to the history directory, even though it should only move the file there at midnight (and rename it with date extension). That's how log4cxx does it, at least :)

    I don't follow why the filename would be user-.log, would you mind explaining that? Would file file be in /xxx/log/, or in /xxx/log/history/?

    For logrotate, am I correct in thinking that manually invoking file rotation will not actually rotate anything, but just reopens the logfile?

     

Log in to post a comment.