[Box Backup] Logging
Chris Wilson
boxbackup@fluffy.co.uk
Thu, 18 May 2006 23:36:25 +0000 (GMT)
Hi Martin,
> Looks fine. Just a couple of minor things:
> - Syslog(), Add(), etc. should presumably be public
Yes, you're absolutely right, sorry!
> - Not sure that the Syslog() and Console() methods are really of any
> benefit. I would think that using Add() directly would be just as easy
The problem is the lifetime of the logger object. We're going to keep a
reference to the object passed in, so it must outlive any uses of it.
However, console or syslog logging would typically be started when the
application starts, perhaps before any objects are instantiated.
You might also want to start logging to the console in main(), and stop in
Daemon::Main(), just after a successful fork(). But I can't see a clean way
for Daemon::Main and main() to share a reference to a Logger object.
Therefore, I was planning to hide the default console logger and the
default syslog logger inside the Log class as private static members - is
that possible? Otherwise I could keep them in auto_ptrs and create them
when Log::ToSyslog() or Log::ToConsole() is first called. I added a couple
of methods to set the log level on the console and syslog. Perhaps we
don't need Add() and Remove() for now?
By the way, one thing I changed from your spec was the BOX_LOG macro. I
changed __FUNCTION__ to __FILE__, since __FUNCTION__ on its own isn't very
helpful in tracking down which file the offending code is located in (I
think). I'm also assuming that both __FILE__ and __LINE__ can be converted
to std::string without problems.
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 |