Menu

Target Parameter in Settings File crashes application on termination

2013-10-14
2013-10-14
  • Ivan Suricz

    Ivan Suricz - 2013-10-14

    Hello,

    I have a really weired problem with the Target parameter in the following settings file:

    Global core parameters

    [Core]
    DisableLogging=false
    Filter="%Severity% >= TRACE"

    Rolling sink is a default sink for detailed

    [Sinks.Rolling]
    Destination=TextFile
    FileName="log/voxModule_%Y%m%d_%H%M%S.%N.log"
    Target="log"
    RotationSize=1048576
    MaxSize=3145728
    Filter="%Severity% >= TRACE"
    Format="%RecordID%: %TimeStamp% %Severity% %ThreadID% | %Tag% | %Message%"
    Asynchronous=false
    AutoFlush=true

    ...

    As long as I don't specify the Target parameter the following application executes and terminates completely normal without any problems, but when I add the Target="log" parameter to the settings file like shown above the application still executes normally till the mains return 0; expression and then crahes for an unknown reason! All log files are written correctly but the clean up for some reason crahes! Can anyone have a look at settings file config and the source where the problem comes from? Thanks for any help in advance.

    // Here we define our application severity levels.
    enum severity_level {
    trace,
    debug,
    info,
    warn,
    error
    };

    BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::severity_logger_mt< severity_level >)

    // The output stream operator for severity
    template< typename CharT, typename TraitsT >
    inline std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& stream, severity_level const& level) {
    static const char const levelString[] = {
    "TRACE",
    "DEBUG",
    "INFO ",
    "WARN ",
    "ERROR"
    };
    if (static_cast< std::size_t >(level) < (sizeof(levelString) / sizeof(
    levelString))) {
    stream << levelString[level];
    } else {
    stream << static_cast< int >(level);
    }
    return stream;
    }

    // The input stream operator for severity
    template< typename CharT, typename TraitsT >
    inline std::basic_istream< CharT, TraitsT >& operator>> (std::basic_istream< CharT, TraitsT >& stream, severity_level& level) {

    std::string levelString;
    stream >> levelString;
    
    if ( levelString.compare ( "TRACE" ) == 0 ) {
        level = trace;
    } else if ( levelString.compare ( "DEBUG" ) == 0 ) {
        level = debug;
    } else if ( levelString.compare ( "INFO" ) == 0 ) {
        level = info;
    } else if ( levelString.compare ( "WARN" ) == 0 ) {
        level = warn;
    } else if ( levelString.compare ( "ERROR" ) == 0 ) {
        level = error;
    }
    
    return stream;
    

    }

    // a helper for getting the current ThreadID
    unsigned long getHumanReadableThreadID() {
    std::string threadId = boost::lexical_cast<std::string>(boost::this_thread::get_id());
    unsigned long convertedThreadID = 0;

    std::istringstream stringToLongConverter(threadId.c_str());
    stringToLongConverter >> std::hex >> convertedThreadID;
    return convertedThreadID;
    

    }

    // logging capsule
    template<unsigned int="" Id="0">
    class Logging {

    public:

    void initialize () {
    
        logging::register_simple_formatter_factory<severity_level, char>("Severity");
        logging::register_simple_filter_factory<severity_level, char>("Severity");
    
        // Open the one and only logging configuration file
        std::ifstream settings("BoostLogDemoLog.properties");
        if (!settings.is_open())
        {
            std::cout << "Could not open settings.txt file" << std::endl;
            return;
        }
    
        // Read the settings and initialize logging library plain
        logging::init_from_stream(settings);
    
        // Attribute for counting total lines of log records
        attrs::counter< unsigned int > RecordID(1);
        logging::core::get()->add_global_attribute("RecordID", RecordID);
    
        // Attribute for time stamp of log records
        attrs::local_clock TimeStamp;
        logging::core::get()->add_global_attribute("TimeStamp", TimeStamp);
    
        // Attribute for thread ID where the log records comes from
        logging::core::get()->add_global_attribute("ThreadID",  attrs::make_function(&getHumanReadableThreadID));
    }
    

    };

    // shortcuts

    define BOOST_LOG_TRACE( t ) { BOOST_LOG_SCOPED_THREAD_TAG("Tag", BOOST_CURRENT_FUNCTION); BOOST_LOG_SEV(my_logger::get(), trace) << t; }

    define BOOST_LOG_DEBUG( t ) { BOOST_LOG_SCOPED_THREAD_TAG("Tag", BOOST_CURRENT_FUNCTION); BOOST_LOG_SEV(my_logger::get(), debug) << t; }

    define BOOST_LOG_INFO( t ) { BOOST_LOG_SCOPED_THREAD_TAG("Tag", BOOST_CURRENT_FUNCTION); BOOST_LOG_SEV(my_logger::get(), info) << t; }

    define BOOST_LOG_WARN( t ) { BOOST_LOG_SCOPED_THREAD_TAG("Tag", BOOST_CURRENT_FUNCTION); BOOST_LOG_SEV(my_logger::get(), warn) << t; }

    define BOOST_LOG_ERROR( t ) { BOOST_LOG_SCOPED_THREAD_TAG("Tag", BOOST_CURRENT_FUNCTION); BOOST_LOG_SEV(my_logger::get(), error) << t; }

    int main(int argc, char* argv[]) {

    Logging<> loggingInst;
    loggingInst.initialize();
    
    BOOST_LOG_ERROR ( "A fatal error occurred here" );
    
    std::cout << "here" << std::endl;
    
    return 0;
    

    }

    Best regards

     
  • Andrey Semashev

    Andrey Semashev - 2013-10-14

    This problem is a consequence of a bug in Boost.Filesystem. You can work around it by calling core->remove_all_sinks() before leaving main().

     

Log in to post a comment.