[BRLTTY] New logging functionality.

Nicolas Pitre nico at fluxnic.net
Sat May 26 11:31:19 EDT 2012


On Sat, 26 May 2012, Dave Mielke wrote:

> The -l (lowercase), or --log-level=, option now accepts a comma-delimited set 
> of words. Each of these words can be, as before, a log level or number, but can 
> also be the name of a log category. If, for example, you need to log the 
> packets sent to and received from the braille device, you'd specify:
> 
>    -l debug,inpkts,outpkts
> 
> The following log categories have been defined (so far):
> 
>    ingio inpkts outpkts brlkeys kbdkeys csrtrk routing

This is really nice!

Two comments:

One notable absence in those categories appears to be "speech".  
However it is hard to introduce speech event logging as the speech 
driver methods are directly called from all over the place e.g. 
speech->say(...).  It would probably make sense to wrap those calls with 
a common function like speech_say(...) and so on for all speech methods, 
and have speech->say() be called only from there.  Then, logging speech 
events becomes trivial.

Secondly, looking at logRouting(), it might be a good idea to push 
vsprintf usage down into logMessage(), or alternatively to move the log 
level test up, so to avoid wasted CPU cycles doing string formatting if 
the log level is too low and the formatted string won't be used in the 
end.

This could in fact be combined into a single bit mask:

#define LOG_LVL_EMERGENCY	(1 << 0)
#define LOG_LVL_ALERT		(1 << 1)
#define LOG_LVL_CRITICAL	(1 << 2)
...
#define LOG_LVL_DEBUG		(1 << 7)

#define LOG_CTG_INGIO		(1 << 8)
#define LOG_CTG_INPKTS		(1 << 9)
#define LOG_CTG_OUTPKTS		(1 << 10)
... etc.

Then logMessage() becomes:

void logMessage (unsigned int logmask, char *format, ...)
{
  if (!(logmask & activeLogFlags) return;
  ...
}

and

#define logRouting(msg...) \
	logMessage (LOG_LVL_DEBUG|LOG_CTG_ROUTING, "cursor routing: " msg)


Nicolas


More information about the BRLTTY mailing list