Boost logo

Boost :

Subject: [boost] Logging library
From: Tigran Hayrapetyan (tigran.human_at_[hidden])
Date: 2011-06-28 02:49:00


Hello dear Boost community

I'm Tigran Hayrapetyan from Armenia, 22 years old. I have started learning
C++ when I was 14, after 1.5 years practicing on BASIC.
I want introduce to you an idea related to logging, that I came up with
recently.

Existing logging libraries which I used, are writing log messages linearly,
just one after another.
In contrast, as we know, almost any application's working structure is not
linear, but hierarchical instead, i.e. functions which call other functions,
and so on.
When viewing large log file produced by an application, it is not very
convenient to find log messages of functions, which took middle place in
call hierarchy. Because between that messages there are a lot of other
messages produced by lower-level functions in that hierarchy. So,
generally, it takes some time to understand called functions sequence, and
to find the point from which something goes wrong.
After spending time looking for log messages I need in my applications, I
think that it is possible to organize logging not linearly, but
hierarchically, so the messages will form something like a tree. Log
messages which are related to some subtask, can be grouped as child messages
of the caller task. Also, in my opinion, priority of the caller task's
message can be equal to maximal priority of child messages, so it will show
whole status of that task (higher priority is for more serious messages).

So I decided to implement such logging library. I put it in namespace "tlog"
by now, for "Tree Logging". In my implementation hierarchical messages are
presented in XML format, as it is some standard for tree-like data.
There are two attached files. The library itself is in "tlog.hpp" file, and
"main.cpp" contains a sample application which is using the library and
writes log to "tlog.xml" file. They are written in MS Visual Studio 2008.
Log messages are written with help of 4 macros:

TLOG_INFO( Logger, Text ) : logs message
with specified text to specified logger with priority "information"
TLOG_WARNING( Logger, Text ) : logs message with
specified text to specified logger with priority "warning"
TLOG_ERROR( Logger, Text ) : logs message
with specified text to specified logger with priority "error"
TLOG_SCOPED_NODE( Logger, NodeName ) : opens xml element in the log
file. The element will be closed at the end of scope, so there is no need to
close it manually.

I think that the best way to implement entering/leaving subnodes of the log
file, is to use scopes of the code.

Please review run result and the code, and see if it can be useful for
boost.

Best Regards,
Tigran Hayrapetyan





Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk