Sorry again for newbie question but after spending one day playing with the library and search on the web, I just can't get my rotating log working to append to the last file written.
Here is my code:
//Createatextfilesinktypedefsinks::synchronous_sink<sinks::text_file_backend>file_sink;shared_ptr<file_sink>Fsink(newfile_sink(keywords::file_name="SampleTest_%2N.log",//filenamepatternkeywords::open_mode=(std::ios::out|std::ios::app),keywords::rotation_size=102240//rotationsize,incharacters));//SetupwheretherotatedfileswillbestoredFsink->locked_backend()->set_file_collector(sinks::file::make_collector(keywords::target="logs",//wheretostorerotatedfileskeywords::max_size=1000*1024,//maximumtotalsizeofthestoredfiles,inbyteskeywords::min_free_space=100*1024*1024//minimumfreespaceonthedrive,inbytes));//Uponrestart,scanthetargetdirectoryforfilesmatchingthefile_namepatternFsink->locked_backend()->scan_for_files();//Ok,we're ready to add the sink to the logging library logging::core::get()->add_sink(Fsink); // Now our logs will be written both to the console and to the file. // Let'sdoaquicktestandoutputsomething.Wehavetocreatealoggerforthis.src::loggerlg;BOOST_LOG(lg)<<"Some log line with a counter";//etcetc
As you can tell I already set the open_mode = (std::ios::out | std::ios::app)
as well as calling
Fsink->locked_backend()->scan_for_files();
before the sink the added to the core.
But everytime I start my application, it will start produce a new SampleTest_0X.log file without appending to the last one.
I am using MSVS10, Window 7, Boost 1.51 and the Log package would be the one comes with the package which would be v1.1
Thanks for your time
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When you scan_for_files, the backend selects the next available file counter. This makes the log file name unique each time you start your application, which prevents appending. This is expected.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2013-02-10
Hi, same problem here, and I haven't found a solution yet.
If this is the expected behaviour, is there any way to change it?
For me the typical unix "logrotate-style" would be most interesting, is this somehow possible?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On the second thought, changing this will break the code when collected files are stored in a different directory than the sink target path. So I'm in favor of keeping the current behavior.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2013-02-10
If you add it as an option, e.g. keywords::rotation_mode or something like that?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't think it will be as easy as that. The backend will create a new file with the same name as the file in the storage governed by the file collector, so the files will clash when it comes to file rotation. What you're asking requires a different file backend design, and this is a too radical change to do in v2. Maybe I will come up with another solution later.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all
Sorry again for newbie question but after spending one day playing with the library and search on the web, I just can't get my rotating log working to append to the last file written.
Here is my code:
As you can tell I already set the open_mode = (std::ios::out | std::ios::app)
as well as calling
Fsink->locked_backend()->scan_for_files();
before the sink the added to the core.
But everytime I start my application, it will start produce a new SampleTest_0X.log file without appending to the last one.
I am using MSVS10, Window 7, Boost 1.51 and the Log package would be the one comes with the package which would be v1.1
Thanks for your time
When you scan_for_files, the backend selects the next available file counter. This makes the log file name unique each time you start your application, which prevents appending. This is expected.
Hi, same problem here, and I haven't found a solution yet.
If this is the expected behaviour, is there any way to change it?
For me the typical unix "logrotate-style" would be most interesting, is this somehow possible?
No, this cannot be customized, unless you reimplement file scanning and the file sink backend itself. I will probably change this behavior.
On the second thought, changing this will break the code when collected files are stored in a different directory than the sink target path. So I'm in favor of keeping the current behavior.
If you add it as an option, e.g. keywords::rotation_mode or something like that?
I don't think it will be as easy as that. The backend will create a new file with the same name as the file in the storage governed by the file collector, so the files will clash when it comes to file rotation. What you're asking requires a different file backend design, and this is a too radical change to do in v2. Maybe I will come up with another solution later.