Move logging config to a dictionary

This commit is contained in:
ponas committed 2015-02-18 09:04:52 +01:00
1 parent 7fc85ffd87
commit 43893a8cfa
2 files changed
+39 -17

No files matched your search

+37
View File
@@ -19,6 +19,43 @@ INSIDE_API_KEY = ''
MEMBERSHIP_PRICE_KR = 1
## Logging ##
#############
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'fmt': {
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
},
},
'handlers': {
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'level': 'DEBUG',
'formatter': 'fmt',
'filename': '/tmp/tekstmelding-app.log',
},
'email': {
'class': 'logging.handlers.SMTPHandler',
'level': 'ERROR',
'mailhost': ('localhost', 25),
'fromaddr': 'noreply@example.com',
'toaddrs': ADMINS,
'subject': 'Tekstmelding FAIL',
},
},
'loggers': {
'': {
'handlers': ['file', 'email'],
'level': 'DEBUG',
'propagate': False,
},
}
}
## Sendega ##
#############
+2 -17
View File
@@ -6,6 +6,7 @@ import MySQLdb
import MySQLdb.cursors
import datetime
import logging
import logging.config
from utils import generate_activation_code
import sendega
@@ -17,23 +18,7 @@ app = Flask(__name__)
app.config.from_object('config')
if not app.debug:
# Log INFO and higher levels to stderr
stream_handler = logging.StreamHandler()
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
stream_handler.setFormatter(formatter)
stream_handler.setLevel(logging.INFO)
app.logger.addHandler(stream_handler)
# Email admins about ERRORs and higher levels
from logging.handlers import SMTPHandler
mail_handler = SMTPHandler(
mailhost='127.0.0.1',
fromaddr='noreply+tekstmelding@neuf.no',
toaddrs=app.config['ADMINS'],
subject='Tekstmelding FAIL')
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
logging.config.dictConfig(app.config['LOGGING'])
def connect_db():