Re: Passing information to printf like functions
On Nov 14, 1:14 pm, Gianni Mariani <gi4nos...@mariani.ws> wrote:
James Kanze wrote:
The Austria C++ logging interface does things
differently. This is what a typical "log" looks like:
AT_STARTLOG( l_lm, l_loglevel, AT_LOGLEVEL_SEVERE,"SomeDescription" )
at_log("Some Variable") << 55 << 123.456;
at_log("Some Other Variable") << "YUP";
AT_ENDLOG
-or-
AT_LOG( l_lm, l_loglevel, AT_LOGLEVEL_SEVERE,"SomeDescription" )
Yes, AT_STARTLOG and AT_ENDLOG are macros, there are reasons
why it makes sense to do that too.
If for no other reason that you want to automatically make
__FILE__ and __LINE__ available to the logger.
I'm not sure I like the block, though. I use something like:
LOG( severity ) << ...
The AT_STARTLOG macro is an if that can be used to eliminate
whole levels of logging code - which removes the whole - "I
don't like to do logging because it slows down the code" issue
from the discussion.
That's more or less what I figured.
My own measurements suggest that if the code invoked in the LOG
macro is written carefully, the performance of my version, when
logging is disabled, is not a problem. It resolves to three or
four tests of a boolean, rather than one, but in most contexts,
that's really not worth mentionning. In reality, of course...in
practice, you often have to argue about hypothetical performance
problems in order to get it accepted, and more than once in the
past, I've had to do something like:
LOG( severity, "text" << value ... ) ;
; logging was only "acceptable" if it were possible to compile
it completely out, in order to guarantee 0 overhead. (There are
probably applications where that approach is justified, but I've
never worked on one.)
My experience has been that the more the programmer has to
write to log something, the less will be logged, so I try to
keep it as simple as possible.
If it's a cut-n-paste mostly, then it's not an issue.
It has been for some programmers I've worked with, in the past.
The first time I did the logging interface we did something like:
STARTLOG( ... ) { at_log("A") << aval; }
The problem was the carelessness of the "}" - it was prone to
looking like regular code. We never ever had an issue with
that in the STARTLOG/ENDLOG paradigm.
I agree that your current situation seems better. In some ways,
I almost prefer it to mine. But I've had problems getting even
mine to be used, because it's "too much extra typing".
(Part of the problem might be that in the past, we've never
standardized on an editor. Here, everyone uses either emacs or
vim---perhaps offering configurations for the two which give a
hot key to insert the framework would make it more acceptable.
In the past, however, there have been too many different
editors in use, some not nearly as configurable as emacs or
vim.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34