modification des routes pour les logs
This commit is contained in:
@@ -19,6 +19,7 @@ class BaseConfig(object):
|
|||||||
ADMINS = ['vincent.benoit@benserv.fr']
|
ADMINS = ['vincent.benoit@benserv.fr']
|
||||||
|
|
||||||
LOG_FOLDER = os.path.join(os.getcwd(), 'log')
|
LOG_FOLDER = os.path.join(os.getcwd(), 'log')
|
||||||
|
APP_NAME = "KineIntercom"
|
||||||
|
|
||||||
SECRET_KEY = "d]omg;<*|uHfs}ogN=dk_$YW"
|
SECRET_KEY = "d]omg;<*|uHfs}ogN=dk_$YW"
|
||||||
|
|
||||||
@@ -57,5 +58,5 @@ class DefaultConfig(BaseConfig):
|
|||||||
class ProdConfig(BaseConfig):
|
class ProdConfig(BaseConfig):
|
||||||
ROOT_BASE_FOLDER = "/opt"
|
ROOT_BASE_FOLDER = "/opt"
|
||||||
# Log Folder path
|
# Log Folder path
|
||||||
LOG_FOLDER = os.path.join("/var/log", BaseConfig.PROJECT)
|
LOG_FOLDER = "/var/log"
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def refresh_expiring_tokens(response):
|
|||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
target_timestamp = datetime.timestamp(now + current_app.config['DELTA'])
|
target_timestamp = datetime.timestamp(now + current_app.config['DELTA'])
|
||||||
if target_timestamp > exp_timestamp:
|
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())
|
access_token = create_access_token(identity=get_jwt_identity())
|
||||||
# refresh token in storage place
|
# refresh token in storage place
|
||||||
if os.path.exists(os.path.join("/tmp", current_app.config['PROJECT'])):
|
if os.path.exists(os.path.join("/tmp", current_app.config['PROJECT'])):
|
||||||
@@ -61,10 +61,10 @@ def refresh_expiring_tokens(response):
|
|||||||
except (RuntimeError, KeyError):
|
except (RuntimeError, KeyError):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@log.route('/logs', methods=['GET'])
|
@log.route('/conf_logs', methods=['GET'])
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
def get_all_logs():
|
def get_conf_logs():
|
||||||
''' Retreive app logs '''
|
''' Retreive conf logs '''
|
||||||
# Access the identity of the current user with get_jwt_identity
|
# Access the identity of the current user with get_jwt_identity
|
||||||
current_user = get_jwt_identity()
|
current_user = get_jwt_identity()
|
||||||
|
|
||||||
@@ -78,3 +78,21 @@ def get_all_logs():
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
lines[-1]['msg'] = lines[-1]['msg'] + line
|
lines[-1]['msg'] = lines[-1]['msg'] + line
|
||||||
return jsonify(lines), status.HTTP_200_OK
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user