rakshasa / libtorrent

libTorrent BitTorrent library
http://rtorrent.net/downloads/
GNU General Public License v2.0
885 stars 209 forks source link

Allow log files to be appended #195

Closed nicholi closed 5 years ago

nicholi commented 5 years ago

Rather than current implentation of truncate/overwrite by default.

The only real difference from standard open_file is in the ofstream constructor. Added tests as well.

Makes using simple file names great again, and prevent rtorrent from overwriting all files on a restart. I also ran into a small issue when using logrotate.d and the copytruncate directive. After a log rotation had been performed, and when rtorrent began writing to file again, it wouuld be filled with null 0's up to the last position it had been written to. This would potentially solve that.

rakshasa commented 5 years ago

If we're adding append it should also be done for gzip'ed logs.

Instead of a separate function, pass append as a parameter to both log_open_file and log_open_gz_file.

nicholi commented 5 years ago

Not the greatest C++ dev, but I'm guessing that should just mean passing 'a' to gzopen? The concept of appending to a gzip seems a little weird, but if it works.

I'll re-work the PR to take that into account, both as a parameter. And change up my PR related to this on rtorrent as well.

chros73 commented 5 years ago

@Nicholi , what do you think about @pyroscope's solution instead? It seems way easier, not requireing any new command. I'm not sure about gz type though.

rakshasa commented 5 years ago

@chros73 That has already been merged, this is a different issue as people might want to keep the previous log file content.

Also yes, just add a bool parameter and "a" to gzopen should work.

chros73 commented 5 years ago

@rakshasa , Oh, I see, I can't keep track anymore what's happened :)

nicholi commented 5 years ago

Switched to simple append parameter, with default value of false. Should prevent any API breakage as well.