redirecting stdout/err to mysql table

Aleksandar Radulovic alex at a13x.net
Wed Nov 19 16:55:53 CET 2008


On Tue, Nov 18, 2008 at 7:07 PM, n00b <pyn00b at gmail.com> wrote:
> 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



More information about the Python-list mailing list