Menu

No output on console or file

Anonymous
2012-10-29
2013-06-03
  • Anonymous

    Anonymous - 2012-10-29

    Hi all,

    I've downloaded and compiled successfully the boost.log sources from svn under Windows 7 using mingw-4.7.

    Compilation string for the entire boost-sources including boost.log in the appropriate folders was:

    "bjam --build-type=complete mc-compiler=windmc"
    

    As output I've received : "libboost_log-mgw47-1_51" and "libboost_log_setup-mgw47-mt-1_51".

    IDE: eclipse-juno with CDT

    However I see no output when running the trivial sample code below.

    #include <boost/log/core.hpp>
    #include <boost/log/trivial.hpp>
    #include <boost/log/utility/init/to_console.hpp>
    #include <iostream>
    using namespace boost::log;
    int main(int argc, const char* argv[]) {
        init_log_to_console();
        BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
        BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
        BOOST_LOG_TRIVIAL(info) << "An informational severity message";
        BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
        BOOST_LOG_TRIVIAL(error) << "An error severity message";
        BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
        return 0;
    }
    

    The same applies for the following code-snipped:

    #include <boost/log/core.hpp>
    #include <boost/log/trivial.hpp>
    #include <boost/log/utility/init/to_console.hpp>
    #include <boost/log/utility/init/to_file.hpp>
    #include <iostream>
    using namespace boost::log;
    int main(int argc, const char* argv[]) {
        logging::init_log_to_file("sample.log");
        BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
        BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
        BOOST_LOG_TRIVIAL(info) << "An informational severity message";
        BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
        BOOST_LOG_TRIVIAL(error) << "An error severity message";
        BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
        return 0;
    }
    

    Could some give me a hint why I see nothing on the console?

    Thanks a lot in advance,

    Degoah

     
  • Andrey Semashev

    Andrey Semashev - 2012-10-29

    Could you specify the exact version of Boost.Log you downloaded?

     
  • Anonymous

    Anonymous - 2012-10-30

    Hi andysem,

    I've downloaded the revision 733 from https://boost-log.svn.sourceforge.net/svnroot/boost-log/trunk.

    My boost version is 1.51.0. Compilation works fine, but unfortunately no output on the console or no "sample.log" file is created anywhere in my project directory respectively.

    Thanks so far for your fast answer.

    I've you don'T have any clue, so please let it me also know! So I will switch to another log framework as I've already invested 2 days for boost.log-> with no productive success yet. But I'm confidend, that you will give me a valuable hint!;)

    Bye

     
  • Anonymous

    Anonymous - 2012-10-30

    Hi andysem,

    I've tried the code above on a Ubuntu 12.04 LTS system. Boost version is 1.51.0 and boost.log in revision 733.

    There it works: Output is generated in the console as well as in the sample.log file.

    Nethertheless, it's still necessar to have it also runnable on my windows system. Maybe the compilation of the boost library and the boost.log libraries wasn't performed with the correct parameters, although the mentioned ones

     bjam --build-type=complete mc-compiler=windmc
    

    produced boost libraries without any error.

    Hope you have a way to solve that issue.

    thanks so far,

    Degoah

     
  • Andrey Semashev

    Andrey Semashev - 2012-10-30

    Sorry, I don't have an easy access to a Windows machine. I will probably have a chance to experiment on the weekend.

    In the meantime you can try stepping through the code in the debugger. Does it work if you don't call any init* functions?

     
  • Anonymous

    Anonymous - 2012-10-30

    Hi!

    I've tried your purpose: Running without the init-functions (init_log_to_console and init_log_to_file). And guess what: It produces an output:

         A trace severity message
         A debug severity message
          An informational severity message
       A warning severity message
         An error severity message
         A fatal severity message

    Great, if you have time and you get a windows machine, so please try to figure out why the way with the init-functions doesn't procude any output. In the meanwhile I'll use the debugger and figure out what is going on out there;)

    Bye,

    Degoah

     
  • Anonymous

    Anonymous - 2012-10-31

    Hi!

    I works now. I'm not sure why, but it works.

    What I've done was to delete all boost-libraries and to build the boost-framework again with this command string:

    bjam --build-type=minimal toolset=gcc mc-compiler=windmc
    

    The compilation procedure finished without any big issue and the two boost.log libraries ""libboost_log-mgw47-1_51" and "libboost_log_setup-mgw47-mt-1_51" were created.

    I've linked the example code above with the following libraries

    boost_system-mgw47-mt-1_51
    boost_log-mgw47-mt-1_51
    boost_log_setup-mgw47-mt-1_51
    boost_regex-mgw47-mt-1_51
    boost_date_time-mgw47-mt-1_51
    boost_thread-mgw47-mt-1_51
    boost_chrono-mgw47-mt-1_51

    In the 1st run I've received the following error message from the linker:

    boost_1_51_0/boost/thread/tss.hpp:105: undefined reference to `__imp___ZN5boost6detail12set_tss_dataEPKvNS_10shared_ptrINS0_20tss_cleanup_functionEEEPvb'

    I've figured out, that this is a bug in the thread library, which just appears on some platforms.

    https://svn.boost.org/trac/boost/ticket/4921
    https://svn.boost.org/trac/boost/ticket/4258

    A proposed solution was to define the following preprocessor symbol

    #define BOOST_THREAD_USE_LIB 1
    

    in the code.

    After this the sample code compiled successfully and gave me the output below:

    A trace severity message
    A debug severity message
    An informational severity message
    A warning severity message
    An error severity message
    A fatal severity message

    Thanks so far!

     
  • Andrey Semashev

    Andrey Semashev - 2012-10-31

    Are you sure you have libboost_log-mgw47-1_51 and not libboost_log-mgw47-mt-1_51? It seems odd you get non-multithreaded binary for Boost.Log and not for the rest of Boost.

     
  • Anonymous

    Anonymous - 2012-11-05

    Hi,

    after starting the building process with the following parameters

    bjam -build-type=minimal toolset=gcc mc-compiler=windmc

    I've received the "libboost_log-mgw47-mt-1_51" binary file. Previously (mentioned in my first post), I've received a non-multithreaded library of Boost.Log.

    Greetings

     
  • Anonymous

    Anonymous - 2012-11-22

    Hi once again:)!

    if I execute the following code

    int main(void)
    {
       src::logger slogger;
       logging::add_common_attributes();
       logging::init_log_to_console();
       BOOST_LOG(slogger) << "Initiation of main";
       BOOST_LOG(slogger) << "Take off!";
       return 0;
    }
    

    …i just receive the following output:

    Initiation of main
    Take off!

    But where are the common attribute outputs like "LineID", "TimeStamp", "ProcessID" and "ThreadID"?
    I understood, that when I call "logging::add_common_attributes();" I will receive this information on each log record additionally to my specific output strings.

    Thanks in advance for your help!

    Greetings,

    Degoah

     
  • Andrey Semashev

    Andrey Semashev - 2012-11-22

    You have to set up a formatter in order the attributes to appear in the output. The add_common_attributes function only adds the attributes to the core, it doesn't set up a formatter.

     
  • Anonymous

    Anonymous - 2012-11-22

    Thanks for your fast response.

    Does this even fit to the use of channel loggers? For example:

    class Airplane{
        src::channel_logger< > m_logger;
    public:
        Airplane() : m_logger(keywords::channel = "Airplane") {}
        void setFuelLevel(int fuel){
            BOOST_LOG(m_logger) << "SetFuelLevel";
        }
        int getPassenger();
    private:
        int m_fuel;
    };
    

    I would now expect such an output with the correctly setup of a formatter:

    Airplane: SetFuelLever

    I understand the channel logger as a possibilty to have the string, which was defined in the channel logger's constructor, on every log record. Is this correct? Ok, if i use the correct formatter too!?????

    Thanks in advance for your help!

     
  • Anonymous

    Anonymous - 2012-11-22

    I think, I've got it how to output the channel string:

    Please consider the following code snippet

    int main(void)
    {
         src::channel_logger< > slogger(keywords::channel = "Pilot");
         logging::add_common_attributes();
         logging::init_log_to_file("logger.log", keywords::format = "[%Channel%, TimeStamp]: %_%");
         BOOST_LOG(slogger) << "Initiation of main";
       return 0;
    }
    

    The attribute name to be used within the formatter to get the channel string was just "Channel".

    I hope, this is the correct way, or is there a better approach?

    Thank you so far for your hint regarding the formatter.

    I think I've now understand the basic concept behind attributes and the formatter in boost.log:

    Attributes are used as the keyword( placeholders) for the formatter and the filter logic. Every attribute defined can be used in the formatter or as keyword for the filters.

    Sometimes it would be better, if the documentation would be read carefully and not just fluffy;)

    Best regards from Germany!

     

Log in to post a comment.