Daemon and logging - the best approach?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-2?Q?Lech_Karol_Paw=B3aszek?=

    Daemon and logging - the best approach?

    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]
  • J Kenneth King

    #2
    Re: Daemon and logging - the best approach?

    Lech Karol Pawłaszek <i@tak.znajdzie szwrites:
    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.

    Comment

    • =?UTF-8?B?TGVjaCBLYXJvbCBQYXfFgmFzemVr?=

      #3
      Re: Daemon and logging - the best approach?

      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]

      Comment

      • Neal Becker

        #4
        Re: Daemon and logging - the best approach?

        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:

        Comment

        • Lawrence D'Oliveiro

          #5
          Re: Daemon and logging - the best approach?

          In message <gf1m17$qpc$1@z eus.man.szczeci n.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?

          Comment

          • =?UTF-8?B?TGVjaCBLYXJvbCBQYXfFgmFzemVr?=

            #6
            Re: Daemon and logging - the best approach?

            Lawrence D'Oliveiro wrote:
            In message <gf1m17$qpc$1@z eus.man.szczeci n.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:


            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]

            Comment

            Working...