Re: How to implement diagnostic messages?
- From: BGB <cr88192@xxxxxxxxxxx>
- Date: Thu, 08 Sep 2011 10:57:25 -0700
On 9/8/2011 6:58 AM, Rui Maciel wrote:
In some applications it's useful to have, at least in the development
stages, a way to output diagnostic messages in order to help developers
check what's happening under the hood. Yet, although this can be useful and
in some times even invaluable, there isn't much information on what are
considered to be good practices regarding the implementation of diagnostic
messages.
With this in mind, what are your views on how to implement diagnostic
messages? Are simple outputs to stderr enough or are there better ways to
handle this?
the great problems with stderr:
the messages are not recorded anywhere (can't look over them in more detail later);
in graphical and/or GUI applications, stdout and stderr tend to go nowhere, so anything sent there is not visible.
in my own apps, I tended to just use printf a lot.
eventually, I made a macro which hooked printf to one of my own functions, and mostly ended up just redirecting its output to a log file and to an in-program console (in addition to stdout).
this way, for an app, one can typically see messages in-program, or if there is too much output, go and look over the recorded log-file.
later, I also added a "dbgprintf" function, which also accepts an integer parameter giving its "debug level" (IIRC, number+flags), but have not ended up widely using it.
the idea here would be that dbgprintf would also redirect to the console, and to the log file, but that the debug-level could be used to cull lower-priority messages.
IIRC, level 0 was equivalent to a printf, and 1..N (limit not set, maybe 7 or 15) indicate progressively lower-priority messages.
a message with a greater debug-level than the present debug-level will simply be discarded (neither shown in console, nor logged).
an unaddressed issue is "where" the messages are from, which often matters a lot more than some global "debug level" (one tends to care a lot more about messages from the components they are debugging, without having to necessarily see a mountain of messages for whatever else is going on, like other components loading/saving files, messages from the sound mixer, ...).
the current practice, for the most part, is a bit less organized, and mostly involves manually adding/commenting/uncommenting printf calls.
or such...
.
- Follow-Ups:
- Re: How to implement diagnostic messages?
- From: Rui Maciel
- Re: How to implement diagnostic messages?
- From: Ben Bacarisse
- Re: How to implement diagnostic messages?
- References:
- How to implement diagnostic messages?
- From: Rui Maciel
- How to implement diagnostic messages?
- Prev by Date: How to implement diagnostic messages?
- Next by Date: Re: How to implement diagnostic messages?
- Previous by thread: How to implement diagnostic messages?
- Next by thread: Re: How to implement diagnostic messages?
- Index(es):
Relevant Pages
|