logging and daemons

Discussion in 'Python' started by Fernando M. Maresca, Feb 16, 2009.

  1. Hello.

    I'm in the process of replacing a custom logger class in one of my apps
    that has several daemons. In the last step of daemonizing a program,
    after closing fds, stderr and stdout are redirected to the logfile of
    the program.

    Now, I'm trying to use TimedRotatingFileHandler as the only channel when
    the programs run in daemon mode. My problem is: I can't see a goog way
    to redirect stderr/stdout both to the logger.

    Note that I don't have any print statements in any of my code, but I
    can't be sure about all the modules I'm importing, and I like to get any
    uncached exception info that may go to stderr/stdout to show up in the
    logfiles.

    Any ideas?
    Thanks a lot,

    --
    Fernando

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkmZY84ACgkQCtDmpVXdEMbwLQCfewl3PUrGvT1tkywj3LExUBUd
    SjsAn0pdBXgShSy/PV1V6is65HP0IWSC
    =gG12
    -----END PGP SIGNATURE-----
     
    Fernando M. Maresca, Feb 16, 2009
    #1
    1. Advertising

  2. Fernando M. Maresca schrieb:
    > Hello.
    >
    > I'm in the process of replacing a custom logger class in one of my apps
    > that has several daemons. In the last step of daemonizing a program,
    > after closing fds, stderr and stdout are redirected to the logfile of
    > the program.
    >
    > Now, I'm trying to use TimedRotatingFileHandler as the only channel when
    > the programs run in daemon mode. My problem is: I can't see a goog way
    > to redirect stderr/stdout both to the logger.
    >
    > Note that I don't have any print statements in any of my code, but I
    > can't be sure about all the modules I'm importing, and I like to get any
    > uncached exception info that may go to stderr/stdout to show up in the
    > logfiles.


    why don't you just replace the sys.stdout/sys.stdin objects with
    something that is file-like (supports a write-method, that should be
    enough in this case), and then simply write the data arriving to the
    logger instance of your trust.

    If other modules don't get overly tricky to bypass sys.stdout, that
    should capture all you output, regardless of the file descriptor issues.

    In the end, if a 3rd-party-module choses to open a filedescriptor itself
    & write to that, there is nothing you can do about that. But usually,
    they don't behave that way.

    Diez
     
    Diez B. Roggisch, Feb 16, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. about daemons and IPC

    , Aug 27, 2006, in forum: Python
    Replies:
    4
    Views:
    323
    Irmen de Jong
    Aug 29, 2006
  2. PurpleServerMonkey

    Python, Daemons and D-Bus

    PurpleServerMonkey, May 24, 2008, in forum: Python
    Replies:
    3
    Views:
    344
    Diez B. Roggisch
    May 25, 2008
  3. Fernando M. Maresca

    Re: logging and daemons

    Fernando M. Maresca, Feb 16, 2009, in forum: Python
    Replies:
    2
    Views:
    321
    Fernando M. Maresca
    Feb 16, 2009
  4. Cd Cd

    Threads and daemons

    Cd Cd, Sep 12, 2007, in forum: Ruby
    Replies:
    7
    Views:
    145
    Bob Proulx
    Sep 12, 2007
  5. Davertron

    Daemons and Paths

    Davertron, Mar 14, 2009, in forum: Ruby
    Replies:
    3
    Views:
    134
    Davertron
    Mar 16, 2009
Loading...

Share This Page