Simulating logging.exception with another traceback

Joan Miller peloko45 at gmail.com
Sun Feb 7 06:22:59 EST 2010


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 with logging.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



More information about the Python-list mailing list