Re: The usefulness of application logging
Hendrik Schober wrote:
kanze <kanze@gabi-soft.fr> wrote:
Hendrik Schober wrote:
[...]
I wrote a logging lib that allows filtering of log
messages at compile-time and at run-time, both based on
what's the target audience of the messages and their
severity. At least VC8's optimizer is able to completely
remove log statements that are filtered at compile-time.
Run-time filtered messages are optimized so far as they
generate very little code besides an 'if' statement that
determines whether the message is to be discarded.
Presumably, the if is on a single, scalar variable.
if( std::vector<...>::empty() )
That shouldn't be too expensive. In my own implementations, it
usually comes down to something like:
if ( someStaticArray[ N ] != NULL )
where N is the log level---normally a constant.
I've still not found a good solution for this when there is a
requirement to be able to change the configuration on the fly in
a multithreaded environment. You certainly don't want a lock in
the if (although at least under Solaris, it isn't that
expensive), so you've got to find some way of suspending all
threads other than the one doing the modification, AND ensuring
that all of the other threads correctly synchronize their memory
after the suspention. The only thing I've found so far is for
the updating thread to post a request in a well known place, and
all other threads to periodically poll and suspend themselves if
the request is present. The updating thread then waits until
all threads are suspended, does the update, and then signals the
threads to continue. While this is fairly easy to do using
conditions in Posix, it results in a lot of coupling; in
particular, the updating thread must know how many other threads
there are, and the other threads must explicitly collaborate.
Is this library available somewhere on the network. [...]
No it's not. Somone whose opinion I value high already
tried to make me write an article about it and publish
the code, but I so far haven't got around doing it... :(
I understand the problem. All too well, in fact.
In my own case, I've finally resorted to just making the code
and what documentation I've had the chance to write available
(at http://kanze.james.neuf.fr, at least for the moment), as is,
on the odd chance that it might be useful. What I'd like to do
is update at least the important parts to Boost's standards, and
move it into Boost, but if I wait until I've the time for that,
who knows when it would be available.
If you want I could outline my solution. I don't think
it's all that inventive and you shouldn't have any
problems to come up with your own. (Although it heavily
relies on template-meta stuff and I remember you saying
the compilers you use aren't very good with templates.
It's a while since I regularily read here, though, so
meanwhile this might have changed.)
It's not so much a question of my needing it myself. I've
obviously got a system that works, and since we don't turn
logging completely off in the production code, we obviously
aren't going to compile it out. But it seems like the sort of
thing that would be generally useful. For various reasons, the
logging code in all of the applications I've worked on has
contained some proprietary code which I can not make public.
And yours sounds more flexible than mine anyway.
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]