When using a streamed initialisation there doesn't appear to be any way to setup logfile appending.
The encapsulation of core.cpp and init_from_settings means that a great deal of code duplication is necessary to achieve what is a very small modification.
Please let me know whether there is any obvious way of doing this which I have missed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you mean you can't setup appending to the log file when using init_from_settings? This will be provided in v2. In v1 you can register your own sink factory to configure the file sink the way you want. Search the forum, it's been brought up more than once.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
init_from_settings.cpp:
// Append
it = params.find(constants::append_param_name());
if (it != params.end() && !it->second.empty() && any_cast_to_bool(constants::auto_flush_param_name(), it->second))
{
backend->set_open_mode(std::ios_base::out | std::ios_base::app);
}
This appears to provide me with the functionality I need.
It does appear to have a bug in that it is checking on the autoflush variable rather than the append variable.
If so it may be worth fixing.
Please advise whether this change is going into v2 of boost log.
If this is not the solution for v2 then please advise of what the syntax in the init stream will be so that I can emulate it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, this is going to be available in v2. The any_cast_to_bool argument mistake is not essential, it will only affect error messages. This code is reworked in bleeding-edge, so the mistake will be fixed after merge.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Andrey can you please tell me if this is currently available, maybe you can direct me. I'm using boost 1.59 in Linux environment. I have searched though many threads for long time now with no luck. Basically my project requires following: asynchronous logging set date time stamp from configuration file set severity filter for sinks or core from configuration file set_open_mode to append (log file rotation is not important right now) auto_flush from configuration file Current implementation set date time stamp programmatically ( set severity filters programmatically set_open_mode to append programmatically
* autoflush programmatically
I hope you can help without having me provide source code (company policy does not allow sharing of source code) but I can think of something. I'm posting this from personal laptop. We are switching from log4cpp and boost::log is 40-60% faster, excellent API. Thanks
Last edit: mzazi 2017-08-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Fantastic! It worked, I'm able to read from settings file and still use asynchrounous sink, autoflush and appends to log existing log on restart. I used my own defined sink. Thank you very much my friend....
PS: I apologize for the hijack
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When using a streamed initialisation there doesn't appear to be any way to setup logfile appending.
The encapsulation of core.cpp and init_from_settings means that a great deal of code duplication is necessary to achieve what is a very small modification.
Please let me know whether there is any obvious way of doing this which I have missed.
Do you mean you can't setup appending to the log file when using init_from_settings? This will be provided in v2. In v1 you can register your own sink factory to configure the file sink the way you want. Search the forum, it's been brought up more than once.
Thanks for the speedy reply.
I saw rpodactor's question in the forum however it was about 2 years old.
I've been looking at revision 728 of boost log in the svn repository and found the following:
parser_utils.hpp:
static const char_type* append_param_name() { return L"Append"; }
init_from_settings.cpp:
// Append
it = params.find(constants::append_param_name());
if (it != params.end() && !it->second.empty() && any_cast_to_bool(constants::auto_flush_param_name(), it->second))
{
backend->set_open_mode(std::ios_base::out | std::ios_base::app);
}
This appears to provide me with the functionality I need.
It does appear to have a bug in that it is checking on the autoflush variable rather than the append variable.
If so it may be worth fixing.
Please advise whether this change is going into v2 of boost log.
If this is not the solution for v2 then please advise of what the syntax in the init stream will be so that I can emulate it.
Yes, this is going to be available in v2. The any_cast_to_bool argument mistake is not essential, it will only affect error messages. This code is reworked in bleeding-edge, so the mistake will be fixed after merge.
Andrey can you please tell me if this is currently available, maybe you can direct me. I'm using boost 1.59 in Linux environment. I have searched though many threads for long time now with no luck. Basically my project requires following:
asynchronous logging
set date time stamp from configuration file
set severity filter for sinks or core from configuration file
set_open_mode to append (log file rotation is not important right now)
auto_flush from configuration file
Current implementation set date time stamp programmatically (
set severity filters programmatically
set_open_mode to append programmatically
* autoflush programmatically
I hope you can help without having me provide source code (company policy does not allow sharing of source code) but I can think of something. I'm posting this from personal laptop. We are switching from log4cpp and boost::log is 40-60% faster, excellent API. Thanks
Last edit: mzazi 2017-08-17
asynchronous logging - yes, http://www.boost.org/doc/libs/1_64_0/libs/log/doc/html/log/detailed/sink_frontends.html#log.detailed.sink_frontends.async
set date time stamp from configuration file - not sure what this means, timestamps are generated from the local clock. If you mean timestamp format then out of the box the timestamp format is not read from the config file but the library can be extended to do that: http://www.boost.org/doc/libs/1_64_0/libs/log/doc/html/log/extension/settings.html#log.extension.settings.adding_support_for_user_defined_types_to_the_formatter_parser
set severity filter for sinks or core from configuration file - yes, http://www.boost.org/doc/libs/1_64_0/libs/log/doc/html/log/detailed/utilities.html#log.detailed.utilities.setup.settings, http://www.boost.org/doc/libs/1_64_0/libs/log/doc/html/log/detailed/utilities.html#log.detailed.utilities.setup.filter_formatter
set_open_mode to append - yes, from the API. See above about extending setings parser if support for config file is needed.
auto_flush from configuration file - yes, both from the API and config, http://www.boost.org/doc/libs/1_64_0/libs/log/doc/html/log/detailed/utilities.html#log.detailed.utilities.setup.settings
PS: Please, don't hijack unrelated threads.
Fantastic! It worked, I'm able to read from settings file and still use asynchrounous sink, autoflush and appends to log existing log on restart. I used my own defined sink. Thank you very much my friend....
PS: I apologize for the hijack