Question

I need to aggregate many log files into a single log.

I tried to do this with boost::filesystem::copy_file but it doesn't support appending.

Any ideas? (I'm preferring doing this via boost libraries)

Tnx

Was it helpful?

Solution

You don't need Boost for this simple task - the standard iostream will do the job:

#include <fstream>
//...
using std::ifstream;
using std::ofstream;
ifstream input1("input1.log"), input2("file2.log");
// append to an existing file
ofstream output("output.log", ofstream::out | ofstream::app);
output << input1.rdbuf() << input2.rdbuf();
//...

(Note however that the above approach may have suboptimal performance; take a look at this answer to see how to improve the performance.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top