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

Re: redirecting stdout/err to mysql table

P: n/a
On Tue, Nov 18, 2008 at 7:07 PM, n00b <py****@gmail.comwrote:
greetings,

i need to log to the db directly and wrote a little script to do so.
since i'm pretty new to python,
i was wondering if a) you could review the enclosed code and b)
provide suggestions to harden to code to turn it into a more general,
broadly reusable class.
First of all, your code is not quite pythonic and it will also open the
connection to the database *every* time you log. That can be quite
expensive and generally is not advisable. Plus it may block your code.

I suggest checking out (already existing) logging module in Python
distribution and extend the BaseHandler to implement the logging to
a database.

I highly recommend implementing pooling of connections to the DB
(ie. by simply using SqlAlchemy instead of direct MySQLDb module).

--
a lex 13 x
http://www.a13x.info
Nov 19 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I've had a similar requiredment and made a small tool for direct
logging into databases (see:
http://sourceforge.net/projects/rrlog/
)

It's origins are somewhat older than the Python 2.3 standard logging
framework, so it can be used without that (but can also be simply
integrated with it.) It even does some more than you currently need
(log rotation and remote logging).

Ratsberg
Nov 20 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.