Skip to content

Commit 9110aba

Browse files
committed
better logging for the api
1 parent 30b5d95 commit 9110aba

5 files changed

Lines changed: 15 additions & 7 deletions

File tree

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
NB_WORKERS=6
22
MAXTIME=120
33
SECRET_KEY=DEFAULT_KEY
4+
## if you want to change the log level DEBUG INFO WARNING ERROR CRITICAL
5+
#LOG_LEVEL=INFO
46
## If you want to disable the hack for html line to make thing work when html start with <ul><li>
57
#DISABLE_HTML_HACK=True

API/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Copyright (C) 2023 Probesys
33
"""
44

5-
from flask import Response, send_file
5+
from flask import Response, send_file, current_app
66

77
import lotemplate as ot
88

@@ -180,8 +180,7 @@ def fill_file(directory: str, file: str, json, error_caught=False) -> Union[tupl
180180
"""
181181
if isinstance(json, list):
182182
json=json[0]
183-
print("####\nUsing a list of dict is DEPRECATED, you must directly send the dict.")
184-
print("See documentation.\n#######")
183+
current_app.logger.warning("DEPRECATED Using a list of dict is DEPRECATED, you must directly send the dict. See documentation.")
185184
cnx = connexion()
186185
global scannedjson
187186
try:

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ The upgrade documentation is in the file [UPGRADE.md](UPGRADE.md).
88
Versions 2.x
99
------------
1010

11+
- V2.2.2 : 2025-12-12
12+
- add better logs for the api using logging
13+
1114
- v2.2.1 : 2025-11-03
1215
- FIX : Sort variable to avoid sub string replacement
1316

app.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Copyright (C) 2023 Probesys
33
"""
44

5-
from flask import Flask,request, jsonify,after_this_request,send_file
5+
from flask import Flask,request, jsonify,after_this_request,send_file
66
from werkzeug.utils import secure_filename
77

88
import os
@@ -15,6 +15,10 @@
1515
from lotemplate import statistic_open_document,clean_old_open_document
1616

1717
app = Flask(__name__)
18+
if os.getenv('LOG_LEVEL') :
19+
app.logger.setLevel(os.getenv('LOG_LEVEL'))
20+
else:
21+
app.logger.setLevel('ERROR')
1822

1923
@app.route("/", methods=['PUT', 'GET'])
2024
def main_route():
@@ -111,7 +115,7 @@ def delete_tmp_file(response):
111115
try:
112116
os.remove(file)
113117
except Exception:
114-
print("Error delete file " + str(file))
118+
app.logger.error("Error delete file " + str(file))
115119
return response
116120
if request.headers.get('secretkey', '') != os.environ.get('SECRET_KEY', ''):
117121
return utils.error_sim(
@@ -142,7 +146,6 @@ def delete_tmp_file(response):
142146
elif request.method == 'POST':
143147
if not request.json:
144148
return utils.error_sim('ApiError', 'missing_json', "You must provide a json in the body"), 400
145-
146149
file ,response = utils.fill_file(directory, file, request.json)
147150
return response
148151
elif request.method == 'DELETE':

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ services:
1313
- NB_WORKERS=$NB_WORKERS
1414
- MAXTIME=$MAXTIME
1515
- DISABLE_HTML_HACK=${DISABLE_HTML_HACK:-}
16-
command: "gunicorn -b 0.0.0.0:8000 app:app"
16+
- LOG_LEVEL=${LOG_LEVEL:-}
17+
command: "gunicorn -b 0.0.0.0:8000 --access-logfile '-' --access-logformat '%(h)s %(l)s %(u)s %(t)s \"%(r)s\" %(s)s %(b)s \"%(f)s\" \"%(a)s\" %(M)s' app:app"

0 commit comments

Comments
 (0)