[Tutor] logging to a database

captnswing captnswing at gmx.net
Sat Nov 12 18:14:39 CET 2005

thanks kent,
I actually got it working!

On 11 nov 2005, at 12.26, Kent Johnson wrote:

> captnswing wrote:
>> Hello all,
>> I would like to log messages to a database (mysql)
>> I found the example log_test14.py that comes with python logging
>> module http://www.red-dove.com/python_logging.html
>> but that example is a bit greek for me ... :) and it doesnt work with
>> mysql
> Have you used mysql from Python before? I looked at that example  
> and it is not that complex if you understand how to program a  
> database. I think what you have to do is
> - install MySQL and create the database table that you want to log  
> to. The SQL statement in the example shows the fields you might  
> want, or you can use a subset of those fields if you don't need so  
> much information.
> - modify the example program a little:
> change
>   import mx.ODBC.Windows
> to the correct import for the MySQL driver
> change
>   self.conn = mx.ODBC.Windows.connect(self.dsn, self.uid, self.pwd)
> to the correct statement to connect to MySQL
> change the SQL statement to correspond to your database schema
> If you *haven't* used MySQL from Python before, you should probably  
> learn a little about the basics first.
> BTW the example is vulnerable to SQL injection attacks - if any of  
> the log messages contain text from user input you should fix that.  
> But get it working first, then come back and ask for help again.
> Kent
> -- 
> http://www.kentsjohnson.com
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list