Commit 6f18c305 authored by David Mendez's avatar David Mendez
Browse files

Add a simple module to handle app logging

parent b65cf182
"""
Entry file for the delayed jobs app
"""
import logging
from flask import Flask, Blueprint
from flask_restplus import Api
......@@ -18,6 +19,7 @@ from app.namespaces.job_statistics.record_download_controller import API as reco
from app.db import DB
from app.config import RUN_CONFIG
from app.config import RunEnvs
import app.app_logging as app_logging
def create_app():
......@@ -31,7 +33,11 @@ def create_app():
flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = RUN_CONFIG.get('sql_alchemy').get('track_modifications')
flask_app.config['SECRET_KEY'] = RUN_CONFIG.get('server_secret_key')
set_up_app_logger(flask_app)
app_logging.debug('This is a Debug Message')
app_logging.info('This is an info Message')
app_logging.warning('This is an warning Message')
app_logging.error('This is an error Message')
app_logging.critical('This is a critial Message')
authorizations = {
'jobKey': {
......@@ -73,20 +79,5 @@ def create_app():
return flask_app
def set_up_app_logger(flask_app):
"""
Sets up the logger for the app
:param flask_app: flask app
"""
print('LOGGING: ')
flask_app.logger.setLevel(20)
flask_app.logger.debug('this is a DEBUG message')
flask_app.logger.info('this is an INFO message')
flask_app.logger.warning('this is a WARNING message')
flask_app.logger.error('this is an ERROR message')
flask_app.logger.critical('this is a CRITICAL message')
if __name__ == '__main__':
flask_app = create_app()
"""
Module that provides logging functions for any other module and adapts to any environment where it is running.
"""
import logging
from app.config import RUN_CONFIG
DEBUG = 'DEBUG'
INFO = 'INFO'
WARNING = 'WARNING'
ERROR = 'ERROR'
CRITICAL = 'CRITICAL'
def debug(msg):
"""
Logs a debug message
"""
log_msg(DEBUG, msg)
def info(msg):
"""
Logs an info message
"""
log_msg(INFO, msg)
def warning(msg):
"""
Logs a warning message
"""
log_msg(WARNING, msg)
def error(msg):
"""
Logs an error message
"""
log_msg(ERROR, msg)
def critical(msg):
"""
Logs a critical message
"""
log_msg(CRITICAL, msg)
def log_msg(level, msg):
"""
Prints a message to the console
"""
logger = RUN_CONFIG.get('logger')
if logger is None:
print(level, ':', msg)
else:
gunicorn_logger = logging.getLogger(logger)
if level == DEBUG:
gunicorn_logger.debug(msg)
elif level == INFO:
gunicorn_logger.info(msg)
elif level == WARNING:
gunicorn_logger.warning(msg)
elif level == ERROR:
gunicorn_logger.error(msg)
elif level == CRITICAL:
gunicorn_logger.critical(msg)
......@@ -8,4 +8,5 @@ elasticsearch:
host: 'the elasticsearch host'
jobs_run_dir: 'Where the job runs'
jobs_scripts_dir: 'Where the job scripts are'
run_jobs: False # If False, do not actually run any job, useful for testing. Assumed to be true if missing.
\ No newline at end of file
run_jobs: False # If False, do not actually run any job, useful for testing. Assumed to be true if missing.
logger: 'gunicorn.error' #Logger to use for the app logs
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment