Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: logging and daemons

Reply
Thread Tools

Re: logging and daemons

 
 
Fernando M. Maresca
Guest
Posts: n/a
 
      02-16-2009
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-----

 
Reply With Quote
 
 
 
 
Vinay Sajip
Guest
Posts: n/a
 
      02-16-2009
On Feb 16, 1:15 pm, "Fernando M. Maresca" <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Fernando M. Maresca
Guest
Posts: n/a
 
      02-16-2009
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)

iEYEARECAAYFAkmZvEcACgkQCtDmpVXdEMbCkACeNukvqslexU NMKcLRpOIgcz32
eZMAnReTgf0eapMsfiy76EE/JL/Dire4
=HMW3
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Daemons and Paths Davertron Ruby 3 03-16-2009 12:48 PM
logging and daemons Fernando M. Maresca Python 1 02-16-2009 05:07 PM
Python, Daemons and D-Bus PurpleServerMonkey Python 3 05-25-2008 11:40 AM
Threads and daemons Cd Cd Ruby 7 09-12-2007 05:20 AM
about daemons and IPC sdistefano@gmail.com Python 4 08-29-2006 05:36 PM



Advertisments