I am using logging in my django project to log errors. However whenever any error occurs at any line, the line number in logs is where the error was logged and not where the error occured.
For example in below code if error occured at 3rd line (code to get data line 1) then in logs line number will be printed as 7 where logging happened.
def get_gender():
try:
# code to get data line 1
# code to get data line 2
# return data dictionary
except Exception as e:
logging.getLogger("error_logger").error(repr(e))
return {}
Below is the code of formatted in logging settings file.
formatters':{
'large':{
'format':'%(asctime)s %(levelname)s %(process)d %(pathname)s '+
'%(funcName)s %(lineno)d %(message)s '
},
Error message example:
2017-05-06 15:20:07,065 ERROR 7000 /home/USER/ASonline/common/services/category_services.py get_gender 7 IndexError('list index out of range',)
How can I get the line number where error occurred instead of line number from where error logged.