Making Python loggers output all messages to stdout in addition to log file

All logging output is handled by the handlers; just add a logging.StreamHandler() to the root logger. Here’s an example configuring a stream handler (using stdout instead of the default stderr) and adding it to the root logger: import logging import sys root = logging.getLogger() root.setLevel(logging.DEBUG) handler = logging.StreamHandler(sys.stdout) handler.setLevel(logging.DEBUG) formatter = logging.Formatter(‘%(asctime)s – %(name)s – … Read more

The shortest possible output from git log containing author and date

git log –pretty=format:”%h%x09%an%x09%ad%x09%s” does the job. This outputs: fbc3503 mads Thu Dec 4 07:43:27 2008 +0000 show mobile if phone is null… ec36490 jesper Wed Nov 26 05:41:37 2008 +0000 Cleanup after [942]: Using timezon ae62afd tobias Tue Nov 25 21:42:55 2008 +0000 Fixed #67 by adding time zone supp 164be7e mads Tue Nov 25 … Read more

How do I log a Python error with debug information?

logger.exception will output a stack trace alongside the error message. For example: import logging try: 1/0 except ZeroDivisionError: logging.exception(“message”) Output: ERROR:root:message Traceback (most recent call last): File “<stdin>”, line 2, in <module> ZeroDivisionError: integer division or modulo by zero @Paulo Cheque notes, “be aware that in Python 3 you must call the logging.exception method just … Read more

When to use the different log levels

I generally subscribe to the following convention: Trace – Only when I would be “tracing” the code and trying to find one part of a function specifically. Debug – Information that is diagnostically helpful to people more than just developers (IT, sysadmins, etc.). Info – Generally useful information to log (service start/stop, configuration assumptions, etc). … Read more

python exception message capturing

You have to define which type of exception you want to catch. So write except Exception, e: instead of except, e: for a general exception (that will be logged anyway). Other possibility is to write your whole try/except code this way: try: with open(filepath,’rb’) as f: con.storbinary(‘STOR ‘+ filepath, f) logger.info(‘File successfully uploaded to ‘+ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)