[Box Backup-dev] Logging

Chris Wilson boxbackup-dev@fluffy.co.uk
Fri, 23 Dec 2005 22:23:55 +0000 (GMT)


Hi all,

The Win32 port has showed up what looks to me like a limitation with the 
logging capabilities of Box. In a number of places, the Box code calls 
fprintf(stderr, ...) or ::syslog(...) or TRACE(...). It's not possible to 
redirect these calls easily to a different destination, or change the 
logging verbosity on the fly (or at all, without recompiling everything).

Under Windows, when running as a service, I'd like to be able to send all 
messages to the Windows event log only (since stderr goes nowhere). When 
running from the command prompt, I'd like to send them both to 
stdout/stderr and the event log - especially for startup errors, since if 
the user double-clicks on bbackupd.exe, the window closes too fast for 
them to read the error message.

I'd like to propose replacing all three current logging methods with 
something like this:

* A global namespace Log:: for logging functions, constants and classes

* A global function Log::Log(priority, format, ...) to send log messages
   to all attached targets

* A global set of priorities: Log::DEBUG, Log::INFO, Log::PROGRESS,
   Log::WARNING, Log::ERROR, Log::FATAL

* Classes for sending log messages to particular destinations (abstract
   Log::Target, implemented by Log::Console and Log::Syslog)

* Global functions to add and remove targets:
   Log::Targets::Add(Log::Target& t), Log::Targets::Remove(...)

* Global instances of Console and Syslog targets (Log::CONSOLE and
   Log::SYSLOG)

* Target method to change verbosity (Log::Target::Filter(priority))

I'd like to change the way that logging is used throughout the code, as 
follows:

* In command-line tools for all platforms, the Console target is added
   immediately at startup.

* In Unix daemons, the Console and Syslog targets are added at startup,
   and the Console target is removed from the child process after the first
   fork.

* In Windows daemons, when running as a service, the Syslog target is
   added at startup.

* In Windows daemons, when running from the command line, the Console and
   Syslog targets are added at startup.

* All TRACE calls are changed to Log::Log(Log::TRACE, ...)

* All fprintf(stderr, ...) calls are changed to Log::Log(Log::ERROR, ...)

* All ::syslog() calls are changed to Log::Log

Does this seem like a reasonable plan? Does anyone have any comments, 
questions or objections? Not answering counts as acceptance in my book :-)

Cheers, Chris.
-- 
_ ___ __     _
  / __/ / ,__(_)_  | Chris Wilson <0000 at qwirx.com> - Cambs UK |
/ (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer |
\ _/_/_/_//_/___/ | We are GNU-free your mind-and your software |