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
#2
I'm beginning to think you don't deserve help. This question was answered as a response to one of your earlier posts.

https://python-forum.io/thread-38648-pos...#pid163942

That was what, 5 days ago?

The same thing happened with this post:

https://python-forum.io/thread-38708.html

Which was answered by me as a response to another of your posts. TWO DAYS AGO!

https://python-forum.io/thread-38682-pos...#pid164101


This page discusses the rules for the forum.

https://python-forum.io/misc.php?action=help

Posted there, under "How to ask Smart Questions" is this:

Quote:Before you ask
Did you search the forum archives for a similar question that was already asked on this forum?
Did you search the web? Google it first.
Did you read the manual?
Did you inspect it yourself and try experimenting?
Did you ask a skilled friend?
Did you read the source code?
You should convey this type of information on your post to not sound like a lazy sponge and wasting volunteer's time.

You are not doing these. Not only did you not search the forum archives for a similar question, you don't even review the responses to your on threads!

And on top of that, your first post was only 2 months ago and you've already started 46 threads asking for help. 46 requests for help but not even 1 attempt to offer aid to anyone else. You start your posts with "Hi Team", but this is no team. This is not how teams work.

Don't be a lazy sponge. Try harder. Much harder.
Reply
#3
Hi deanhystad,

Thanks for the info.

I got it now. its working



Thanks
mg
Reply
#4
You can either pass a logger name or a logger instance to LogError(). By default it will use the base logger (by passing None to logging.getLogger). One could also simply add a switch for raising the error or just logging it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  logger behaviour setdetnet 1 895 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  python insert blank line in logger mg24 1 2,861 Nov-02-2022, 08:36 AM
Last Post: snippsat
  python logger help ... save logger into different folder mg24 1 1,490 Oct-25-2022, 03:04 PM
Last Post: snippsat
  Closing logger from other function problem Paqqno 1 1,126 Apr-25-2022, 11:49 AM
Last Post: Gribouillis
  Closing logger to rename directory malcoverc 1 1,212 Apr-19-2022, 07:06 AM
Last Post: Gribouillis
  pywin32 Illustrator Throwing Exception Error matthewsjc1 7 5,604 Aug-27-2021, 02:43 AM
Last Post: Larz60+
  logger option , where is the file? korenron 1 1,794 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,074 Nov-13-2020, 07:43 AM
Last Post: buran
  SystemError: error return without exception set!!! faryad13 3 3,700 Oct-23-2020, 02:32 PM
Last Post: ATARI_LIVE
  How to assign input file name as logger name Mekala 5 2,878 Aug-05-2020, 12:54 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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