modification des routes pour les logs

This commit is contained in:
2022-10-23 15:38:16 +02:00
parent 8d95860527
commit 323f8c636c
2 changed files with 24 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ class BaseConfig(object):
ADMINS = ['vincent.benoit@benserv.fr']
LOG_FOLDER = os.path.join(os.getcwd(), 'log')
APP_NAME = "KineIntercom"
SECRET_KEY = "d]omg;<*|uHfs}ogN=dk_$YW"
@@ -57,5 +58,5 @@ class DefaultConfig(BaseConfig):
class ProdConfig(BaseConfig):
ROOT_BASE_FOLDER = "/opt"
# Log Folder path
LOG_FOLDER = os.path.join("/var/log", BaseConfig.PROJECT)
LOG_FOLDER = "/var/log"

View File

@@ -49,7 +49,7 @@ def refresh_expiring_tokens(response):
now = datetime.now(timezone.utc)
target_timestamp = datetime.timestamp(now + current_app.config['DELTA'])
if target_timestamp > exp_timestamp:
currenT_app.logger.warning("On doit recréer un token ....")
current_app.logger.warning("On doit recréer un token ....")
access_token = create_access_token(identity=get_jwt_identity())
# refresh token in storage place
if os.path.exists(os.path.join("/tmp", current_app.config['PROJECT'])):
@@ -61,10 +61,10 @@ def refresh_expiring_tokens(response):
except (RuntimeError, KeyError):
return response
@log.route('/logs', methods=['GET'])
@log.route('/conf_logs', methods=['GET'])
@jwt_required()
def get_all_logs():
''' Retreive app logs '''
def get_conf_logs():
''' Retreive conf logs '''
# Access the identity of the current user with get_jwt_identity
current_user = get_jwt_identity()
@@ -78,3 +78,21 @@ def get_all_logs():
except ValueError as e:
lines[-1]['msg'] = lines[-1]['msg'] + line
return jsonify(lines), status.HTTP_200_OK
@log.route('/app_logs', methods=['GET'])
@jwt_required()
def get_app_logs():
''' Retreive app logs '''
# Access the identity of the current user with get_jwt_identity
current_user = get_jwt_identity()
lines = []
with open(os.path.join(current_app.config['LOG_FOLDER'], current_app.config['APP_NAME'] + '.log')) as f:
for idx, line in enumerate(f.readlines()):
try:
date_time, head, gravity, msg = line.split(' - ', 3)
content = {'datetime': date_time, 'header': head, 'gravity': gravity, 'msg':msg}
lines.append(content)
except ValueError as e:
lines[-1]['msg'] = lines[-1]['msg'] + line
return jsonify(lines), status.HTTP_200_OK