[BangPypers] FW: Exception file,lineno,method inforamtion needed

Anand Balachandran Pillai abpillai at gmail.com
Mon Oct 26 13:11:00 CET 2009


Forwarding a question from a friend, since he could not reach the list
due to some reason...

---------------------------------------------------------------------------------------------------
From: edukulla Santhosh kumar <k2_santhosh at yahoo.com>
Subject: Exception file,lineno,method inforamtion needed
To: bangpypers at python.org
Date: Tuesday, October 13, 2009, 12:52 PM

    Hi Team,

    Iam using the logging module of python to log messages to a file.

    I have the following code:

    ###Filename : Method.py
    class _Method:

    def _init_(self):
        self.a = None

    def g(self):
         a = 1/0
         print(a)

    ###Filename: Test.py
    from Method import _Method
    from log import log

    k = _Method()

    def f():
       try:
         k.g()
      except Exception,e:
         log(e)

    Now, the log()  method under Test above is under log.py and uses the
logging module of python with the following format specifications. When we
print the e under log, what i wanted is the information trace pertaining to
Method.py like where actually the line no,filename and module name
information under method.py to be printed. Currently,iam not getting what i
wanted.

    What need to be done to achieve this?
    %(levelno)s
    %(levelname)s
    %(pathname)s
    %(filename)s
    %(module)s
    %(funcName)s
    %(lineno)d
    %(created)f
    %(relativeCreated)d
    %(asctime)s
    %(msecs)d
    %(thread)d
    %(threadName)s
    %(process)d
    %(message)s

    Thanks in Advance!
    Santhosh


More information about the BangPypers mailing list