Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#12369 closed Support Requests (invalid)

In boost::log, how to print extra header line when file rotation/rollover

Reported by: xinyan.zhang@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

I have an extra header line to be written to log file (csv format). It has a special format. How to write this header line every time when log file is rotated/rollover? Thank you. My code is like:

const char *logHeaders = "timestamp,thread,client,message";

...

boost::shared_ptr< sinks::text_file_backend > backend =

boost::make_shared< sinks::text_file_backend >(

logging::keywords::file_name = "myfile_%5N.csv"

logging::keywords::rotation_size = 5 * 1024 * 1024,

logging::keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0), );

Change History (3)

comment:1 by Andrey Semashev, 6 years ago

Resolution: invalid
Status: newclosed

in reply to:  1 comment:2 by anonymous, 6 years ago

Replying to andysem:

See open/close handlers.

http://www.boost.org/doc/libs/1_61_0/libs/log/doc/html/log/detailed/sink_backends.html#log.detailed.sink_backends.text_file

Hi, The example in that link works fine for narrow char. I am using wide char header line. But I can not find the wide char version of text_file_backend::stream_type. Which one shall I use? Thank you.

Your example:

void write_header(sinks::text_file_backend::stream_type& file)
{
    file << "<?xml version=\"1.0\"?>\n<log>\n";
}
...

sink->locked_backend()->set_open_handler(&write_header);

comment:3 by Andrey Semashev, 6 years ago

There is no wide character version as the sink backend already operates on converted characters. If you have national characters in your header/footer you'll have to perform character conversion yourself.

Note: See TracTickets for help on using tickets.