DBHandler class for logging?

K

kj

I've come across mentions of a mythical class of logging handlers
called DBHandler, but I can't find it anywhere.

Could someone please point me in the right direction?

(FWIW, I'm looking for ways to log messages to PostgreSQL RDBMS.)

TIA!

kynn
 
D

Diez B. Roggisch

kj said:
I've come across mentions of a mythical class of logging handlers
called DBHandler, but I can't find it anywhere.

Could someone please point me in the right direction?

(FWIW, I'm looking for ways to log messages to PostgreSQL RDBMS.)

I'm not aware such a thing is part of the standard logging package. But
it's trivial to write one, we did so ourselves. Depending on your
version of python, you need to inject the class into the
logging.handlers-module to make it loadable by the logfile-format. AFAIK
since 2.6 that restriction is gone.

Diez
 
K

kj

I'm not aware such a thing is part of the standard logging package. But
it's trivial to write one, we did so ourselves. Depending on your
version of python, you need to inject the class into the
logging.handlers-module to make it loadable by the logfile-format.

I'm sorry for my ignorance, but what exactly do you mean by
"injecting" the new class into the "logging.handlers-module"? And
what is "the logfile-format"?

TIA!

kynn
 
D

Diez B. Roggisch

kj said:
I'm sorry for my ignorance, but what exactly do you mean by
"injecting" the new class into the "logging.handlers-module"? And
what is "the logfile-format"?

The logfile format as specified in the documentation fo the
logging-module. And due to some restrictions in the way how this
instantiates declared logging-handlers, you need to set your own class
into logging.handlers:

import logging.handlers as h

class MyHandler(...):
...


h.MyHandler = MyHandler


# now you can load the config.

Diez
 
K

kj

In said:
See my answer to a question on Stack Overflow, which has the source
code for a simple handler which writes to a database using the Python
DB-API 2.0:

Although the question relates to Oracle, my answer is not so specific.
It's not production quality code but it should get you started.


Many thanks, to both you and Diez.

kynn
 
N

Nebur

With a similar requirement, I made a small logging tool (usable as
handler) which logs into nearly every DB (including Postgres - thanks
to the SQLAlchemy library.)
It has BSD license. You may use it (or parts of the code):
http://www.reifenberg.de/rrlog/
(It does some more things you may not need, like rotation handling.)
Regards,
Nebur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top