Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 965a436

Browse files
authoredDec 20, 2024··
Merge pull request #49 from daisybio/modules
Add console log
2 parents 2519655 + 55d93be commit 965a436

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎server.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,28 @@
66
import app.config as config
77
import os
88
from connexion.resolver import RelativeResolver
9+
import logging
10+
import sys
11+
from flask import request
912

1013

1114
# Get the application instance
1215
connex_app = config.connex_app
1316

17+
# Configure logging to the console (stdout)
18+
logging.basicConfig(
19+
stream=sys.stdout, # Output to console
20+
level=logging.INFO, # Logging level
21+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
22+
)
23+
logger = logging.getLogger(__name__)
24+
25+
@connex_app.app.before_request
26+
def log_request():
27+
logger.info(f"Incoming request: {request.method} {request.url}")
28+
logger.info(f"Headers: {dict(request.headers)}")
29+
logger.info(f"Body: {request.get_data(as_text=True)}")
30+
1431
# Read the swagger.yml file to configure the endpoints
1532
swagger_file = os.path.join(os.path.dirname(__file__), "swagger.yml")
1633
connex_app.add_api(swagger_file, resolver=RelativeResolver('app.controllers'))

0 commit comments

Comments
 (0)
Please sign in to comment.