Simulating logging.exception with another traceback
Vinay Sajip
vinay_sajip at yahoo.co.uk
Mon Feb 8 16:13:33 EST 2010
On Feb 7, 11:22 am, Joan Miller <pelok... at gmail.com> wrote:
> I would want to get the output from `logging.exception` but with
> traceback from the caller function (I've already all that
> information).
>
> This would be the error withlogging.exception:
> --------------------
> ERROR:
> PipeError('/bin/ls -l | ', 'no command after of pipe')
> Traceback (most recent call last):
> File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line
> 160, in __call__
> raise PipeError(command, 'no command after of pipe')
> PipeError: ('/bin/ls -l | ', 'no command after of pipe')
> --------------------
>
> And I've trying it with:
> --------------------
> message = "File \"{0}\", line {1}, in {2}\n\n {3}".format(
> file, line, function, caller)logging.error(message)
>
> ERROR:
> File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line
> 163, in __call__ return self.throw(PipeError, command, 'no
> command after of pipe')
> --------------------
>
> Could be used `logging.LogRecord` [1] to get it? How?
>
> [1]http://docs.python.org/library/logging.html#logging.LogRecord
Sorry, Joan,
I don't understand your question. Can you create a short script which
throws an exception, and show exactly how you want it formatted?
The logger.exception method does the same as logger.error, except that
it prints exception trace information and is intended to be called
from exception handling clauses. You can format exceptions how you
like by subclassing Formatter and overriding formatException.
Regards,
Vinay Sajip
More information about the Python-list
mailing list