Python Forum
how to write exception error into logger
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to write exception error into logger
#1
Hi Team,

I am unable to write error message into logger my logger file.

I am generating error , I can print that error.
I cannot write that error into logger file.
str obj as no attribute 'info'



logger.info(f"----------> connecting to database") such type of message I can write to logger


My attempted code.


import sys
import traceback


def error_log(error,logger):
    for e in (error.split('\n')):
        if not "Traceback" in e:
            logger.info("@"*80)
            logger.info(e)
            loger.info("@"*80)
            print("@"*80)
            print(e)
            print("@" * 80)


def func(x):
    try:
        return x / 0
    except Exception as e:
        error = traceback.format_exc()
        error_log(error,logger)
        sys.exit()

if __name__ == "__main__":
    func(10)
Reply


Messages In This Thread
how to write exception error into logger - by mg24 - Nov-15-2022, 04:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to share a configured logger between running processes? somhairle69tx 5 1,984 Sep-06-2024, 11:10 PM
Last Post: somhairle69tx
  logger behaviour setdetnet 1 1,732 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  python insert blank line in logger mg24 1 5,335 Nov-02-2022, 08:36 AM
Last Post: snippsat
  python logger help ... save logger into different folder mg24 1 3,523 Oct-25-2022, 03:04 PM
Last Post: snippsat
  Closing logger from other function problem Paqqno 1 1,905 Apr-25-2022, 11:49 AM
Last Post: Gribouillis
  Closing logger to rename directory malcoverc 1 1,936 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  pywin32 Illustrator Throwing Exception Error matthewsjc1 7 9,348 Aug-27-2021, 02:43 AM
Last Post: Larz60+
  logger option , where is the file? korenron 1 2,599 Apr-25-2021, 01:28 PM
Last Post: snippsat
  I have an index error inline 76 but I write the program in a way that cant reach tha abbaszandi 2 2,953 Nov-13-2020, 07:43 AM
Last Post: buran
  SystemError: error return without exception set!!! faryad13 3 5,471 Oct-23-2020, 02:32 PM
Last Post: ATARI_LIVE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020