Skip to content
Snippets Groups Projects
Commit afd74691 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Rework logging code

parent 9d893db4
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,13 @@ class Config:
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
NOPAQUE_STORAGE = os.environ.get('NOPAQUE_STORAGE')
os.makedirs('logs', exist_ok=True)
logging.basicConfig(filename='logs/nopaque.log',
format='[%(asctime)s] %(levelname)s in '
'%(name)s/%(filename)s, line %(lineno)d:'
'%(message)s',
datefmt='%Y-%m-%d %H:%M:%S', filemode='w')
@staticmethod
def init_app(app):
pass
......@@ -38,19 +45,10 @@ class DevelopmentConfig(Config):
os.environ.get('POSTGRES_USER'),
os.environ.get('POSTGRES_PASSWORD'),
os.environ.get('POSTGRES_DB_NAME'))
if not os.path.isfile('logs/nopaque.log'):
file_path = os.path.join(os.getcwd(), 'logs/nopaque.log')
log = open(file_path, 'w+')
log.close()
if os.environ.get('FLASK_CONFIG') == 'development':
log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
"%(filename)s - %(lineno)d - %(message)s")
logging.basicConfig(filename='logs/nopaque.log', level='WARNING',
format=log_format, datefmt='%Y-%m-%d %H:%M:%S',
filemode='w')
logger = logging.getLogger(__name__)
logger.warning('Logging has started with level WARNING.'
' From development config.')
''' ### nopaque ### '''
NOPAQUE_LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL') or 'DEBUG'
logging.basicConfig(level=NOPAQUE_LOG_LEVEL)
class TestingConfig(Config):
......@@ -71,24 +69,15 @@ class ProductionConfig(Config):
os.environ.get('POSTGRES_PASSWORD'),
os.environ.get('POSTGRES_DB_NAME')
)
if not os.path.isfile('logs/nopaque.log'):
file_path = os.path.join(os.getcwd(), 'logs/nopaque.log')
log = open(file_path, 'w+')
log.close()
if os.environ.get('FLASK_CONFIG') == 'production':
log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
"%(filename)s - %(lineno)d - %(message)s")
logging.basicConfig(filename='logs/nopaque.log', level='ERROR',
format=log_format, datefmt='%Y-%m-%d %H:%M:%S',
filemode='w')
logger = logging.getLogger(__name__)
logger.error('Logging has started with level ERROR.'
' From production config.')
''' ### nopaque ### '''
NOPAQUE_LOG_LEVEL = os.environ.get('NOPAQUE_LOG_LEVEL') or 'ERROR'
logging.basicConfig(level=NOPAQUE_LOG_LEVEL)
config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
'default': DevelopmentConfig,
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment