Discussion:
logging - get source line
Sebastian Elner
13 years ago
Permalink
Hello,

I have an app here, which issues quite a number of sql statements. I
would like to track down where in the code the sql is issued. Setting
echo to True does not give the .py file and line number, so I setup my
own logger as described in the docs:

import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)


adding a format argument to basicLogging for printing the file path and
line number. But I always get base.py and the cursor_execute line.
Any chance of making this work?

Cheer

Sebastian
--
Sebastian Elsner - pipeline td - r i s e | fx

t: +49 30 20180300 ***@risefx.com
www.risefx.com

r i s e | fx GmbH
Schlesische Strasse 28 Aufgang B, 10997 Berlin
Geschäftsführer: Sven Pannicke, Robert Pinnow

Handelsregister Berlin HRB 106667 B
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Michael Bayer
13 years ago
Permalink
I had no idea logging supported such a feature.

However, I do know that intrinsic in a feature like that, is that determining "source line" needs to be configurable via a "depth", that is, how many source lines up should it go up the chain of "sources" for that call, since any particular call to logging will be at the end of a chain of ancestor calls. If this logging feature doesn't support that, then it's kind of useless - use an event handler instead which pulls out the current stack frames and steps upwards the appropriate number of steps before reporting the "source line".
...
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Sebastian Elner
13 years ago
Permalink
Ok, thank you for the advice!
...
--
Sebastian Elsner - pipeline td - r i s e | fx

t: +49 30 20180300 ***@risefx.com
www.risefx.com

r i s e | fx GmbH
Schlesische Strasse 28 Aufgang B, 10997 Berlin
Geschäftsführer: Sven Pannicke, Robert Pinnow

Handelsregister Berlin HRB 106667 B
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Continue reading on narkive:
Loading...