By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,594 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,594 IT Pros & Developers. It's quick & easy.

Daemon and logging - the best approach?

P: n/a
Hello.

I'm trying to make a daemon and I want to log to a file its activity.
I'm using logging module with a configuration file for it (loaded via
fileConfig()).

And now I want to read logging config file before daemonize the program
because the file might not be accessible after daemonization. OTOH while
daemonizing I am closing all opened file descriptors - including those
opened for logging.

What is the best approach to handle such situation? Should I close all
FD before daemonizing or just forget it? Any other hints?

Kind regards,

--
Lech Karol Pawłaszek <ike>
"You will never see me fall from grace" [KoRn]
Nov 7 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Lech Karol Pawłaszek <i@tak.znajdzieszwrites:
Hello.

I'm trying to make a daemon and I want to log to a file its activity.
I'm using logging module with a configuration file for it (loaded via
fileConfig()).

And now I want to read logging config file before daemonize the program
because the file might not be accessible after daemonization. OTOH while
daemonizing I am closing all opened file descriptors - including those
opened for logging.

What is the best approach to handle such situation? Should I close all
FD before daemonizing or just forget it? Any other hints?

Kind regards,
Depends.

For *NIX systems, it's a good idea to use the syslog daemon for logging
where it's available.

I believe the logging module can be configured to log to the local
syslog daemon.

Cheers.
Nov 7 '08 #2

P: n/a
J Kenneth King wrote:
[...]
Depends.

For *NIX systems, it's a good idea to use the syslog daemon for logging
where it's available.
True, however it's more convenient to have certain application logs in
its own place sometimes.
I believe the logging module can be configured to log to the local
syslog daemon.
Sure it can. I want to log to files though. Or at least I want to make
it configurable so one can choose a) log to files b) log via syslog.

I've found delay parameter for FileHandler, however it's only in 2.6 at
the moment and I need 2.5 and I am not so sure if it helps here. Tough life.

Kind regards,

--
Lech Karol Pawłaszek <ike>
"You will never see me fall from grace" [KoRn]
Nov 7 '08 #3

P: n/a
Lech Karol Pawłaszek wrote:
Hello.

I'm trying to make a daemon and I want to log to a file its activity.
I'm using logging module with a configuration file for it (loaded via
fileConfig()).

And now I want to read logging config file before daemonize the program
because the file might not be accessible after daemonization. OTOH while
daemonizing I am closing all opened file descriptors - including those
opened for logging.

What is the best approach to handle such situation? Should I close all
FD before daemonizing or just forget it? Any other hints?

Kind regards,
I use this, YMMV:

Nov 7 '08 #4

P: n/a
In message <gf**********@zeus.man.szczecin.pl>, Lech Karol Pawłaszek wrote:
And now I want to read logging config file before daemonize the program
because the file might not be accessible after daemonization.
Why might it be inaccessible just because you've daemonized?
Nov 7 '08 #5

P: n/a
Lawrence D'Oliveiro wrote:
In message <gf**********@zeus.man.szczecin.pl>, Lech Karol Pawłaszek wrote:
>And now I want to read logging config file before daemonize the program
because the file might not be accessible after daemonization.

Why might it be inaccessible just because you've daemonized?
Well. Just because I always thought one should close all file
descriptors while daemonizing a process.

Just like here:
http://code.activestate.com/recipes/278731/

Lines 160-164.

If one would like to keep logging configuration in a file (like me),
what is supposed to do? Not to close FDs? Or just start logging after
daemonizing (and know absolute location of the logging configuration file)?

Or maybe is there any way to close FD for a logfile, daemonize and
reopen FD again?

;-) Am I clear now?

Kind regards,

--
Lech Karol Pawłaszek <ike>
"You will never see me fall from grace" [KoRn]
Nov 7 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.