Skip to content
Snippets Groups Projects
Commit 2991082f authored by Stephan Porada's avatar Stephan Porada :speech_balloon:
Browse files

Add different logging levels.

parent 682ca309
No related branches found
No related tags found
No related merge requests found
...@@ -40,13 +40,15 @@ class DevelopmentConfig(Config): ...@@ -40,13 +40,15 @@ class DevelopmentConfig(Config):
file_path = os.path.join(os.getcwd(), 'logs/opaque_web.log') file_path = os.path.join(os.getcwd(), 'logs/opaque_web.log')
log = open(file_path, 'w+') log = open(file_path, 'w+')
log.close() log.close()
log_format = ("%(asctime)s - %(levelname)s - %(name)s - " if os.environ.get('FLASK_CONFIG') == 'development':
"%(filename)s - %(lineno)d - %(message)s") log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
logging.basicConfig(filename='logs/opaque_web.log', level='WARNING', "%(filename)s - %(lineno)d - %(message)s")
format=log_format, datefmt='%Y-%m-%d %H:%M:%S', logging.basicConfig(filename='logs/opaque_web.log', level='WARNING',
filemode='w') format=log_format, datefmt='%Y-%m-%d %H:%M:%S',
logger = logging.getLogger(__name__) filemode='w')
logger.warning('Logging has started with level WARNING.') logger = logging.getLogger(__name__)
logger.warning('Logging has started with level WARNING.'
' From development config.')
class TestingConfig(Config): class TestingConfig(Config):
...@@ -71,13 +73,15 @@ class ProductionConfig(Config): ...@@ -71,13 +73,15 @@ class ProductionConfig(Config):
file_path = os.path.join(os.getcwd(), 'logs/opaque_web.log') file_path = os.path.join(os.getcwd(), 'logs/opaque_web.log')
log = open(file_path, 'w+') log = open(file_path, 'w+')
log.close() log.close()
log_format = ("%(asctime)s - %(levelname)s - %(name)s - " if os.environ.get('FLASK_CONFIG') == 'production':
"%(filename)s - %(lineno)d - %(message)s") log_format = ("%(asctime)s - %(levelname)s - %(name)s - "
logging.basicConfig(filename='logs/opaque_web.log', level='ERROR', "%(filename)s - %(lineno)d - %(message)s")
format=log_format, datefmt='%Y-%m-%d %H:%M:%S', logging.basicConfig(filename='logs/opaque_web.log', level='ERROR',
filemode='w') format=log_format, datefmt='%Y-%m-%d %H:%M:%S',
logger = logging.getLogger(__name__) filemode='w')
logger.error('Logging has started with level ERROR.') logger = logging.getLogger(__name__)
logger.error('Logging has started with level ERROR.'
' From production config.')
config = { config = {
......
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