PDA

View Full Version : qlogsystem - java style logging library for C++



Tomicooler
1st March 2015, 09:32
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.



LOG::Manager::Locker locker;
locker.mutable_logger("main")->set_formatter(new LOG::StandardLogFormatter());
locker.mutable_logger("main")->set_output(LOG::IODeviceOutput::create_from_file(s tdout));
locker.mutable_logger("main")->set_level(LOG::DEBUG);

locker.mutable_logger("main.sub")->set_output(LOG::IODeviceOutput::create_from_file("logoutput.txt"));
locker.mutable_logger("main.sub")->set_level(LOG::DUMP);


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.



int twenty = 20;
QString key("value");
QRect rect(0, 0, 100, 100);

log_info("main", 1, "log message - parameters without name", P1(key), P1(twenty), P1(rect));
log_debug("main", 2, "log message - parameters with name", P2("name", 5), P2("key", "value"), P2("rect", QRect(2, 3, 5, 5)));

const quint8 hexdump[] = {0x01, 0x00, 0x0b, 0x00, 0x00, 0x00, ..., 0x01 };

log_debug("main.sub", 3, "here is a hexdump of some data");
log_hexdump("main.sub", 4, hexdump, sizeof(hexdump));


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.

anda_skoa
2nd March 2015, 12:58
Have you registered it with inqlude.org?

Cheers,
_

Tomicooler
4th March 2015, 10:29
I haven't heard about inqlude.org yet, thanks for the hint. I will register the project on it.