Skip to main content

All Questions

0 votes
0 answers
170 views

python: Handling log output of module during program execution

I'm setting up a logger in my script like shown at the bottom. This works fine for my purposes and logs my __main__ log messages and those of any modules I use to stdout and a log file. During program ...
squarespiral's user avatar
37 votes
3 answers
31k views

Python logging exception

I'm currently writing a wrapper class. I want to be able to log exceptions properly but allow calling methods to be aware of exceptions which occur. My class looks like this: import logging log = ...
user avatar
272 votes
10 answers
112k views

Logging uncaught exceptions in Python

How do you cause uncaught exceptions to output via the logging module rather than to stderr? I realize the best way to do this would be: try: raise Exception, 'Throwing a boring exception' ...
Jacob Marble's user avatar
  • 30.3k
792 votes
17 answers
748k views

How do I log a Python error with debug information?

I am printing Python exception messages to a log file with logging.error: import logging try: 1/0 except ZeroDivisionError as e: logging.error(e) # ERROR:root:division by zero Is it possible ...
probably at the beach's user avatar
962 votes
16 answers
1.6m views

python exception message capturing

import ftplib import urllib2 import os import logging logger = logging.getLogger('ftpuploader') hdlr = logging.FileHandler('ftplog.log') formatter = logging.Formatter('%(asctime)s %(levelname)s %(...
Hellnar's user avatar
  • 65k
136 votes
5 answers
179k views

How to log python exception? [duplicate]

How can I log an exception in Python? I've looked at some options and found out I can access the actual exception details using this code: import sys import traceback try: 1/0 except: ...
Maxim Veksler's user avatar
14 votes
5 answers
8k views

python logger logging same entry numerous times

I have a such logger initializing function: def generate_logger(): import logging LOG_FILENAME = os.path.join(PROJECT_DIR, "mylog.log") FORMAT = "%(asctime)s : %(message)s&...
Hellnar's user avatar
  • 65k
47 votes
5 answers
158k views

How to log error to file, and not fail on exception

I am downloading a file from the net, and it fails even though I am doing: for p in query: try: except IOError as e: print e; If there is an error, I want to log it, and then ...
Blankman's user avatar
  • 268k
258 votes
13 answers
273k views

Log exception with traceback in Python

How can I log my Python exceptions? try: do_something() except: # How can I log my exception here, complete with its traceback?
TIMEX's user avatar
  • 273k
82 votes
3 answers
53k views

How do I log an exception at warning- or info-level with traceback using the python logging framework?

Using something like this: try: # Something... except Exception as excep: logger = logging.getLogger("component") logger.warning("something raised an exception: " + excep) logger.info("...
Morten Holdflod Møller's user avatar