G2log with Clang., Now with all the bells and whistles

At reddit I found that it was possible to get futures and std::thread to play nice on Linux/Clang.

I have updated my previous post “g2log with Clang++” with the details so that you can get Linux/Clang (and g2log) with all the bells and whistles of C++11.

All the clang limitations on G2log is therefore removed and Clang users can now enjoy the fully featured G2log.

I am currently working with G3log  and Clang. So far G3log supports Windows (VS2013, mingw) and Linux (g++) and I hope to get Clang up and running.

Advertisements

About kjellkod

Software Engineer by trade, (former?) Martial Artist and Champion by strong will and small skill... and a Swede by nationality :)
This entry was posted in C++, G2log. Bookmark the permalink.

10 Responses to G2log with Clang., Now with all the bells and whistles

  1. Hi, I downloaded g2log from http://www.codeproject.com/KB/library/g2log/KjellKod-g2log-d4518b302cc8.zip but not able to compile it using gcc4.8. Does it have dependency on gcc4.7? I have followed the exact steps as per the readme file. Also there is no information available on errors while compiling g2log. Please assist

    • kjellkod says:

      Hi Kunal,
      The zip file at codeproject contains a very early version of g2log. It is even possible that the version you downloaded required the (back then the only) C++11 concurrency library implementation by just::thread.

      Now there are much better support for C++11 and later releases of g2log does not need just::thread. Please download or fork the latest version of g2log from Bitbucket. https://bitbucket.org/KjellKod/g2log

      g2log is a light-weight and efficient logger that saves your log entries, asynchronously to file. It has compiler support for multiple platforms, and is used by many companies and research institutions world-wide.

      If you later need to create your own custom made log receiving “sinks” you might want to take a look at g3log. https://bitbucket.org/KjellKod/g3log. It requires more C++11 support than g2log so you need at least gcc4.8.

  2. Also, there seems to be no documentation on how to use g2log from C code. Please point me to any resource you may have

  3. kjellkod says:

    If you with C mean C++ then you can check :

    1) CodeProject article you visited or the my mirror http://www.kjellkod.cc/g2log-efficient-background-io-processign-with-c11

    2) The CMakeFiles.txt inside g2log

    3) The g2log/test_example/main.cpp

    4) The Readme/front page at the BitBucket repository, https://bitbucket.org/KjellKod/g2log. Currently it does not show code examples but it points out several links that does.

    If you with C mean C and not C++ then the reason for not providing any documentation in this regard is because I have not envisioned using this C++ logger in a raw C project.

  4. Pietro says:

    Hi kjellkod.

    g2log/g3log seem to be the most interesting loggers I have seen so far. Before discovering them, I was thinking to follow this approach to improve performance: log to a ram-disk, and let an external executable deal with copying the ram-disk based log file on a real disk (or on a DB) at fixed time steps or when the ram-disk file reached a certain size.

    One advantage of this approach is that it allows to use and improve the performance of any existing logger, and all I need to implement is the trivial external copier.
    What are the advantages of your g3log tool when compared to my approach?

    Thank you.

    • kjellkod says:

      G2log writes to disk but g3log is logging to whatever and however you want.

      Example of log sinks that I know are used with g3log are
      1) writing to disk just like g2log
      2) pushing log entries to syslog
      3) sending log entries over ZMQ to another process
      4) I also know of a case where they use g3log to send data to Memcached/Redis

      So with g3log you have the freedom to do whatever. Your approach would certainly be easy to use together with g3log

      Cheers
      Kjell

  5. Bhargavi says:

    Hi KjellKod,

    I downloaded g3log from https://bitbucket.org/KjellKod/g3log. When I try compiling the source code in linux(Ubuntu), I face build issues.
    The gcc version is 4.73
    Below is build issue I get

    Scanning dependencies of target g3logger
    [ 5%] Building CXX object CMakeFiles/g3logger.dir/src/g2loglevels.cpp.o
    [ 11%] Building CXX object CMakeFiles/g3logger.dir/src/g2time.cpp.o
    [ 16%] Building CXX object CMakeFiles/g3logger.dir/src/g2logmessagecapture.cpp.o
    [ 22%] Building CXX object CMakeFiles/g3logger.dir/src/g2logworker.cpp.o
    In file included from /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2sinkhandle.hpp:15:0,
    from /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2logworker.hpp:24,
    from /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2logworker.cpp:14:
    /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2sink.hpp: In instantiation of âg2::internal::Sink::Sink(std::unique_ptr, DefaultLogCall) [with DefaultLogCall = void (g2::FileSink::*)(g2::MoveOnCopy); T = g2::FileSink]â:
    /usr/local/lib/gcc/x86_64-unknown-linux-

    [ … content cut ….. ]

    gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr.h:599:39: required from âstd::shared_ptr std::allocate_shared(const _Alloc&, _Args&& …) [with _Tp = g2::internal::Sink; _Alloc = std::allocator<g2::internal::Sink >; _Args = {std::unique_ptr<g2::FileSink, std::default_delete >, void (g2::FileSink::*&)(g2::MoveOnCopy)}]â
    /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/shared_ptr.h:615:42: required from âstd::shared_ptr std::make_shared(_Args&& …) [with _Tp = g2::internal::Sink; _Args = {std::unique_ptr<g2::FileSink, std::default_delete >, void (g2::FileSink::*&)(g2::MoveOnCopy)}]â
    /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2logworker.hpp:83:75: required from âstd::unique_ptr<g2::SinkHandle > g2::LogWorker::addSink(std::unique_ptr, DefaultLogCall) [with T = g2::FileSink; DefaultLogCall = void (g2::FileSink::*)(g2::MoveOnCopy)]â
    /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2logworker.cpp:128:107: required from here
    /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2sink.hpp:48:78: error: cannot allocate an object of abstract type âg2::internal::SinkWrapperâ
    In file included from /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2logworker.hpp:23:0,
    from /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2logworker.cpp:14:
    /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2sinkwrapper.hpp:17:12: note: because the following virtual functions are pure within âg2::internal::SinkWrapperâ:
    /home/bchanakesapura/ONEM2M/KjellKod-g3log-a9adc750721c/g2log/src/g2sinkwrapper.hpp:19:20: note: virtual void g2::internal::SinkWrapper::send(g2::LogMessageMover)
    make[2]: *** [CMakeFiles/g3logger.dir/src/g2logworker.cpp.o] Error 1
    make[1]: *** [CMakeFiles/g3logger.dir/all] Error 2
    make: *** [all] Error 2

    Any idea on whats wrong? The same code when I compile using visualstudio solution in windows works fine.

    Thanks
    Bhargavi

    • kjellkod says:

      Hi Bhargavi,

      I tried with g++ 4.7.3 without any problems. I will try to test more later … Are you sure about the g++ version?

      • Bhargavi says:

        Hi Kjell,

        Sorry the gcc version Iam using is 4.7.2.
        I followed the steps given in the CMakeLists.txt for the build.
        # === LINUX: === To try this out from folder g2log:
        # mkdir build
        # cd build
        # >> create makefiles in g2log/build directory
        # cmake -DCMAKE_BUILD_TYPE=Release ..
        # make

        Also, the Ubuntu version used is 12.04.1

        I even tried building with USE_SIMPLE_EXAMPLE set to OFF. But the result remains the same.

        Thanks,
        Bhargavi

      • kjellkod says:

        Hi Bhargavi,

        My suggestion is for you to update compiler. There were several important fixes from gcc 4.7.2 to 4.7.3. With the latest Ubuntu the current compiler is 4.8 I believe, but on a newer ubuntu you can still install g++ 4.7 (apt-get install g++-4.7 gcc-4.7). This however gives you the version g++/gcc 4.7.3 not 4.7.2. This is likely due to the important bugfixes between these two versions.

        I see two options for you.
        1) Update your compiler to at least one version up or…
        2) Use g2log instead of g3log which you currently are trying to compile. g2log is less bleeding edge and I hope it should work better for you.

        g2log can be found here: https://bitbucket.org/KjellKod/g2log

        I double checked on an Ubuntu VM (14.4) that both g3log and g2log worked with g++4.7.3. If you have multiple compilers on your Ubuntu then you could compile it with something like this:
        cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++-4.7 .."

        Good luck
        / Kjell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s