Menu

Logging Append mode via stream setup

abcdef
2012-09-28
2013-06-03
  • abcdef

    abcdef - 2012-09-28

    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.

     
  • Andrey Semashev

    Andrey Semashev - 2012-09-28

    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.

     
  • abcdef

    abcdef - 2012-10-01

    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.

     
  • Andrey Semashev

    Andrey Semashev - 2012-10-01

    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.

     
  • mzazi

    mzazi - 2017-08-17

    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
  • mzazi

    mzazi - 2017-08-17

    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

     

Log in to post a comment.