How to configure boost log, for writing with rotating and appending?

前端 未结 1 1777
忘了有多久
忘了有多久 2021-02-13 09:30

How to configure boost log, for writing with rotating and appending?

And after restart program, don\'t clear log file.

int init_log()
{
    typedef sinks         


        
相关标签:
1条回答
  • 2021-02-13 09:56

    Please try this out (the key is adding the log name using some pattern and not fixing its name like "app.log") this will enable flre rotation and the data will be appended to each created file. Regarding the log clearing, as long as you haven't specified custom file_collector, your logs should remain intact :)

    typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
    boost::shared_ptr< file_sink > sink( new file_sink(
            keywords::file_name     = "app%m%d%Y_%H%M%S_%5N.log",   // file name pattern
            keywords::rotation_size = 10*1024                       // rotation size, in characters
            ));
    
    0 讨论(0)
提交回复
热议问题