logging - Logger for python. Doesn't log custom log entries -


for python project have simple logger looks this:

#!flask/bin/python flask import flask,request, response import os.path import json import sys import logging import logging.handlers dbmongomanager import savetomongo dbsqlmanager import savetomysql failedrequest import failedrequest jsonvalidation import validatejson    #create logger logger = logging.getlogger('werkzeug') #defines logger file , max size handler = logging.handlers.rotatingfilehandler('request.log',maxbytes=5000000) #define logger format formatter = logging.formatter("test %(asctime)s [%(threadname)-12.12s] [%(levelname)-5.5s]  %(message)s") handler.setformatter(formatter) #add loggerhandler applications logger.addhandler(handler) app.logger.addhandler(handler)  logger.info("logger started") ... #app implementation here . 

the file request.log gets created, entry "logger started" nowhere. althought events flask (server startet/stopped, request responses) logged. custom logs (logger.info, logger.warning, etc..) appear in file. mistake? example i've seen apparently work implementation.

content off log after reloading script:

2015-04-01 08:54:52,479 [mainthread  ] [info ]   * detected change in '/usr/local/bin/restservice/restservice.py', reloading 2015-04-01 08:55:08,393 [thread-1    ] [info ]  194.209.7.10 - - [01/apr/2015 08:55:08] "post / http/1.1" 400 - 2015-04-01 08:55:08,559 [thread-1    ] [info ]  194.209.7.10 - - [01/apr/2015 08:55:08] "post / http/1.1" 400 - 

this should work

import logging import logging.handlers  # create logger root_logger = logging.getlogger() root_logger.setlevel(0) # defines logger file , max size handler = logging.handlers.rotatingfilehandler('request.log', maxbytes=5000000) # define logger format formatter = logging.formatter("test %(asctime)s [%(threadname)-12.12s] [%(levelname)-5.5s]  %(message)s") handler.setformatter(formatter) handler.setlevel(0) # add loggerhandler applications root_logger.addhandler(handler)  logger = logging.getlogger('app')  logger.info("logger started") 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -