Re: logging and daemons

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

  1. Hello, thanks for the answer.

    On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote:
    > You can actually set sys.std[err|out] to your ?file? descriptor of
    > choice in python (it has to have read, write, and flush methods, IIRC
    > to function). The only thing is (like all things dealing with multiple
    > file descriptors like std[err|out]) the output may come in out of
    > order due to flushing and insertion into the buffers, but it shouldn't
    > be as much of an issue considering that the file descriptor for both
    > items is the same descriptor, but this is just a note of forewarning.

    Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
    fd of the logfile change in every rotation of the logfile. So the direct
    approach of std[out|err] redirection to the logfile fd obtained from
    the logger instance is unusable (it works fine with a simple file
    handler).
    I'm looking into this because I really need rotating, because when
    debugging is on, large amounts of data are logged, and because I like
    the logging module approach in every aspect.

    Also, may it be possible to derive the class and add a file-like write
    method? Anyone using logging in this manner?


    Cheers,
    --
    Fernando

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

    iEYEARECAAYFAkmZZuIACgkQCtDmpVXdEMbdDQCfe6G71RdO/h0Pb95VXSiL5DPc
    tuYAn3DKnh5ugtC0YLHbe/QlggBaVztO
    =35CA
    -----END PGP SIGNATURE-----
     
    Fernando M. Maresca, Feb 16, 2009
    #1
    1. Advertising

  2. Fernando M. Maresca

    Vinay Sajip Guest

    On Feb 16, 1:15 pm, "Fernando M. Maresca" <> wrote:
    > Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
    > fd of the logfile change in every rotation of the logfile. So the direct
    > approach of std[out|err] redirection to the logfile fd obtained from
    > the logger instance is unusable (it works fine with a simple file
    > handler).


    That's fine with a FileHandler, as long as you don't use e.g.
    logrotate - that would cause the fd to change, too.

    > I'm looking into this because I really need rotating, because when
    > debugging is on, large amounts of data are logged, and because I like
    > the logging module approach in every aspect.
    >


    You can capture the stuff written to std[out|err] using any file-like
    object, so there are other options beyond redirecting to the fd of the
    handler's fd or adding a write method to the logger. For example, if
    you create a simple class which duck-types the file-like object, you
    could create two instances, for stdout and stderr, and wire them into
    sys. At any point you choose, you can choose to forward the
    information collected to the log. Is all your stuff pure Python, or do
    you have C extensions or subprocesses which are C-based? Also, I
    assume you have a separate rotating log file per daemon - is that
    right?

    Regards,

    Vinay Sajip
     
    Vinay Sajip, Feb 16, 2009
    #2
    1. Advertising

  3. On Mon, Feb 16, 2009 at 10:11:51AM -0800, Scott David Daniels wrote:
    > Fernando M. Maresca wrote:
    > On Mon, Feb 16, 2009 at 05:07:45AM -0800, Garrett Cooper wrote:
    >>> You can actually set sys.std[err|out] to your ?file? descriptor of
    >>> choice in python ....

    >> Yes, but I'm trying to use *TimedRotating*FileHandler, which makes the
    >> fd of the logfile change in every rotation of the logfile. So the direct
    >> approach of std[out|err] redirection to the logfile fd obtained from
    >> the logger instance is unusable (it works fine with a simple file
    >> handler).

    >
    > Right, so you stick something in as stderr/stdout that talks to the
    > logfile. That is, something like:
    >
    > import sys
    >
    > class MyFakeStdout(object):
    > def flush(self):
    > pass
    > def write(self, text):
    > <code to actually do the logging>
    > sys.stderr = sys.stdout = MyFakeStdout()
    >

    Thanks a lot for the input.
    That's pretty much what I'm doing right now, just wondered if were a
    cleanest way.

    Cheers,

    --
    Fernando

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

    iEYEARECAAYFAkmZvEcACgkQCtDmpVXdEMbCkACeNukvqslexUNMKcLRpOIgcz32
    eZMAnReTgf0eapMsfiy76EE/JL/Dire4
    =HMW3
    -----END PGP SIGNATURE-----
     
    Fernando M. Maresca, Feb 16, 2009
    #3
    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:
    346
    Diez B. Roggisch
    May 25, 2008
  3. Fernando M. Maresca

    logging and daemons

    Fernando M. Maresca, Feb 16, 2009, in forum: Python
    Replies:
    1
    Views:
    297
    Diez B. Roggisch
    Feb 16, 2009
  4. Cd Cd

    Threads and daemons

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

    Daemons and Paths

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

Share This Page