Menu

LOG(fatal) << "fatal msg" implementation suggestion

Help
shahes
2022-10-20
2022-10-21
  • shahes

    shahes - 2022-10-20

    Hi, I was wondering if you have any suggestions on how to correctly implement a fatal log message using the multi-threaded severity logger without creating a special macro for the FATAL condition.

    Thank you.

     
    • Andrey Semashev

      Andrey Semashev - 2022-10-20

      What's wrong with BOOST_LOG_SEV(lg, fatal) << "Good bye cruel world"?

       
      😄
      1
  • shahes

    shahes - 2022-10-21

    Well, for one thing the program keeps running. :-)
    We would like FATAL to call abort or terminate after the log message is written and all the log messages are flushed.
    Unless we missed something, the log library does not do this for you.

     
    • Andrey Semashev

      Andrey Semashev - 2022-10-21

      It's not the logging library's job to terminate the application. If you want to terminate then go ahead and do that - in the application. You may want to call core::flush() to make sure all log records are processed.

       
  • shahes

    shahes - 2022-10-21

    Hi, yes, I agree the library should not terminate but I was wondering if you had a suggestion on the best way to implement the termination. We have tried a callback to std::terminatewith a call to core::flush() and nothing is output to the logs. We have done this with special macro for the fatal severity. We would prefer to not have a special macro. I thought you might have a suggestion on the best way to implement such a feature using features of the library. Thanks

     
    • Andrey Semashev

      Andrey Semashev - 2022-10-21

      A special macro or function seems like the right way to go. Terminating from within the library will not guarantee that all log records are processed. Also, calling core::flush() from an atexit handler won't work because the library is likely terminated at this stage.

       
  • shahes

    shahes - 2022-10-21

    Ok, thank you for the input.

     

Log in to post a comment.