Skip to content

Commit

Permalink
old logger changed
Browse files Browse the repository at this point in the history
  • Loading branch information
seiferta committed May 10, 2015
1 parent 714312b commit 195a402
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions emonitor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def configure_extensions(app):
# flask-sqlalchemy
db.init_app(app)
db.app = app
db.create_all()

with app.app_context():
if alembic.context.get_current_revision() != current_app.config.get('DB_VERSION'): # update version
Expand Down Expand Up @@ -216,21 +217,22 @@ def filter(self, logRecord):
return logRecord.levelno == self.__level

formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
tornadologger = logging.getLogger('tornado.access')
accesslogger = logging.getLogger('werkzeug')

if app.debug:
tornadologger.propagate = False
file_handler = RotatingFileHandler('%s%s-access.log' % (app.config.get('PATH_DATA'), app.name), maxBytes=1024 * 1024 * 100, backupCount=20)
accesslogger.propagate = False
file_handler = RotatingFileHandler('{}{}-access.log'.format(app.config.get('PATH_DATA'), app.name), maxBytes=1024 * 1024 * 100, backupCount=20)
file_handler.setFormatter(formatter)
tornadologger.addHandler(file_handler)
accesslogger.addHandler(file_handler)
app.logger.addHandler(accesslogger)

# set debug mode to all other loggers of emonitor, use loglevel definition of emonitor.cfg
for l in [l for l in logging.Logger.manager.loggerDict if l.startswith(app.name.lower())]:
lo = logging.getLogger(l)
if lo.level > logging.DEBUG:
lo.setLevel(app.config.get('LOGLEVEL', logging.DEBUG))
else:
tornadologger.setLevel(logging.ERROR)
accesslogger.setLevel(logging.ERROR)

logger = logging.getLogger('alembic.migration')
logger.setLevel(logging.ERROR)
Expand Down

0 comments on commit 195a402

Please sign in to comment.