Skip to content
22 changes: 21 additions & 1 deletion backend/restapi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from flask import Flask, request, jsonify
from flasgger import Swagger
from submodule.rs_device_manager import RsDeviceManager
from submodule.rs_logger import log_setup, log, RsLogLevel
from api.device import device_api
from api.clock import clock_api
from api.dsp import dsp_api
Expand All @@ -27,11 +28,17 @@
parser.add_argument('device_file', type=str, help='Path to the input device xml file')
parser.add_argument('--port', type=int, default=5000, help='Specify TCP Port to use for REST server')
parser.add_argument('--debug', default=False, action='store_true', help='Enable/Disable debug mode')
parser.add_argument('--logfile', type=str, default="rpe.log", help='Specify log file name')
parser.add_argument('--maxbytes', type=int, default=2048, help='Specify maximun log file size in kilobytes before rollover')
parser.add_argument('--backupcount', type=int, default=20, help='Specify no. of backup log files')
args = parser.parse_args()

# setup app logger
log_setup(filename=args.logfile, max_bytes=args.maxbytes*1024, backup_count=args.backupcount)

# Check if the device_file exists
if os.path.exists(args.device_file) == False:
print(f"ERROR: The file '{args.device_file}' does not exist.")
log(f"Device file '{args.device_file}' does not exist.", RsLogLevel.ERROR)
sys.exit(1)

# Parse Device XML file into Device List
Expand Down Expand Up @@ -64,6 +71,19 @@
app.register_blueprint(attrs_api)
app.register_blueprint(project_api)

# hook up request signal to log request by UI
@app.before_request
def before_request():
log(f"{request.method} {request.url}")

Check warning on line 77 in backend/restapi_server.py

View check run for this annotation

Codecov / codecov/patch

backend/restapi_server.py#L77

Added line #L77 was not covered by tests

@app.after_request
def after_request(response):
log(f"{request.method} {request.url} {response.status_code} - DONE")
return response

Check warning on line 82 in backend/restapi_server.py

View check run for this annotation

Codecov / codecov/patch

backend/restapi_server.py#L81-L82

Added lines #L81 - L82 were not covered by tests

# log app server started
log("App server is running...")

# Start Rest API server
app.run(debug=args.debug, port=args.port)

Expand Down
Loading
Loading