Friday 15 June 2012

c++ - Boost.Log - how to configure a text sink backend to append to rotated files -



c++ - Boost.Log - how to configure a text sink backend to append to rotated files -

i have sinks::text_file_backend sink. have few rotated log files:

mylog001.log, mylog002.log , on

i want sink maintain writing lastly rotated file - mylog002.log, append contents , go on rotation there on.

i have managed findkeywords::open_mode = append appends on top of existing mylogx files, making them larger , of course of study hard read.

can done in boost.log?

that functionality built in text sink, , the documentation includes illustration set file-name pattern , rules rotating @ sizes , times:

// function registers file sink in logging library void init_logging() { boost::shared_ptr< logging::core > core = logging::core::get(); boost::shared_ptr< sinks::text_file_backend > backend = boost::make_shared< sinks::text_file_backend >( // file name pattern keywords::file_name = "file_%5n.log", // rotate file upon reaching 5 mib size... keywords::rotation_size = 5 * 1024 * 1024, // ...or @ noon, whichever comes first keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0) ); // wrap frontend , register in core. // backend requires synchronization in frontend. typedef sinks::synchronous_sink< sinks::text_file_backend > sink_t; boost::shared_ptr< sink_t > sink(new sink_t(backend)); core->add_sink(sink); }

there apparently no way create library append existing files setup. should phone call backend->scan_for_files(); prior constructing sink, shown under "managing rotated files" heading in documentation, prevents library overwriting previous logs before they're due cleanup.

when topic arose on development mailing list in feb 2013, library's author explained adding back upwards appending nontrivial change couldn't made under current design.

c++ boost logging

No comments:

Post a Comment