Results 1 to 3 of 3

Thread: qlogsystem - java style logging library for C++

  1. #1
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Thumbs up qlogsystem - java style logging library for C++

    Hi all,

    I would like to share my project with you guys. We needed a logging solution at my company for multiple C++ projects, so we created qlogsystem. I think it can be useful for other people as well, so we made it public.

    What is qlogsystem?
    -------------------

    qlogsystem is a very efficient and easy to use logger library written in C++ (using the Qt framework). qlogsystem brings Java style logger hierarchy to C++ with a very simple API, which makes possible to use it in libraries too. With a proper logger hierarchy log message can be categorized and filtered in run-time. The format of the log messages and the output can be configured and changed separately. qlogsystem is very fast. The log messages and their parameters are evaluated only if the log level is big enough, so debug messages will not affect the performance much. qlogsystem is thread safe, but locking is done only when needed.

    Key features:
    - easy to use, simple API
    - convenient log macros (messages with parameters)
    - very fast (late parameter evaluation)
    - threadsafe
    - java style logger hierarchy
    - unique id for log messages
    - log format and log output can be tweaked

    Examples
    ---------

    You can find a demo application in the project, so if you need more example check it out.

    Setting up a logger hierarchy. Loggers are identified with a name, sub loggers inherit their parents settings (formatter, output, level), but it can be overridden.

    Qt Code:
    1. LOG::Manager::Locker locker;
    2. locker.mutable_logger("main")->set_formatter(new LOG::StandardLogFormatter());
    3. locker.mutable_logger("main")->set_output(LOG::IODeviceOutput::create_from_file(stdout));
    4. locker.mutable_logger("main")->set_level(LOG::DEBUG);
    5.  
    6. locker.mutable_logger("main.sub")->set_output(LOG::IODeviceOutput::create_from_file("logoutput.txt"));
    7. locker.mutable_logger("main.sub")->set_level(LOG::DUMP);
    To copy to clipboard, switch view to plain text mode 

    Some log examples, P1/P2 macros are really useful. You can call slow functions to get some nice output for the parameters, it won't affect the performance when they are not logged out due to low log level.

    Qt Code:
    1. int twenty = 20;
    2. QString key("value");
    3. QRect rect(0, 0, 100, 100);
    4.  
    5. log_info("main", 1, "log message - parameters without name", P1(key), P1(twenty), P1(rect));
    6. log_debug("main", 2, "log message - parameters with name", P2("name", 5), P2("key", "value"), P2("rect", QRect(2, 3, 5, 5)));
    7.  
    8. const quint8 hexdump[] = {0x01, 0x00, 0x0b, 0x00, 0x00, 0x00, ..., 0x01 };
    9.  
    10. log_debug("main.sub", 3, "here is a hexdump of some data");
    11. log_hexdump("main.sub", 4, hexdump, sizeof(hexdump));
    To copy to clipboard, switch view to plain text mode 

    Project location and license
    --------------------------

    The project is available on GitHub: https://github.com/balabit/qlogsystem
    The project is licensed under LGPL v2.1. Please read the README for building instructions, you can also find out how to make the documentation and run the tests.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qlogsystem - java style logging library for C++

    Have you registered it with inqlude.org?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2015
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qlogsystem - java style logging library for C++

    I haven't heard about inqlude.org yet, thanks for the hint. I will register the project on it.

Similar Threads

  1. Replies: 2
    Last Post: 10th December 2013, 20:58
  2. Replies: 0
    Last Post: 20th July 2013, 04:07
  3. Qt Library on Ubuntu, strange style problem
    By grayfox in forum Qt Programming
    Replies: 5
    Last Post: 27th September 2011, 11:27
  4. Replies: 0
    Last Post: 20th July 2010, 15:30
  5. logging support!!
    By Raajesh in forum Qt Programming
    Replies: 1
    Last Post: 18th June 2008, 20:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.