Skip to content

Commit 443551c

Browse files
Also add request id to log of summary and accessbility requests
1 parent f828d81 commit 443551c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

connection_scan_algorithm/src/transit_routing_http_server.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ int main(int argc, char** argv) {
530530
// Request a summary of lines data for a route
531531
// TODO Copy pasted from v2/route. There's a lot in common, it should be extracted to common class, just the response parser is different
532532
server.resource["^/v2/summary[/]?$"]["GET"]=[&server, &calculator, &dataStatus, &transitData](std::shared_ptr<HttpServer::Response> serverResponse, std::shared_ptr<HttpServer::Request> request) {
533+
// Have a global id to match the requests in the logs
534+
static int summaryRequestId = 0;
533535

534536
std::string response = getFastErrorResponse(dataStatus);
535537

@@ -551,8 +553,9 @@ int main(int argc, char** argv) {
551553
{
552554
parametersWithValues.push_back(std::make_pair(field.first, field.second));
553555
}
556+
int currentRequestId = summaryRequestId++;
554557

555-
spdlog::info("-- calculating summary request --");
558+
spdlog::info("-- calculating summary request -- {}", currentRequestId);
556559

557560
try
558561
{
@@ -572,10 +575,11 @@ int main(int argc, char** argv) {
572575
}
573576
}
574577

575-
spdlog::info("-- summary request complete --");
578+
spdlog::info("-- summary request complete -- {}", currentRequestId);
576579

577580
} catch (NoRoutingFoundException &e) {
578581
response = ResultToV2SummaryResponse::noRoutingFoundResponse(queryParams, e.getReason()).dump(2);
582+
spdlog::info("-- summary request not found -- {}", currentRequestId);
579583
}
580584

581585
*serverResponse << "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: " << response.length() << "\r\n\r\n" << response;
@@ -602,6 +606,8 @@ int main(int argc, char** argv) {
602606
// Routing request for a single origin destination
603607
// TODO Copy-pasted and adapted from /route/v1/transit. There's still a lot of common code. Application code should be extracted to common functions outside the web server
604608
server.resource["^/v2/accessibility[/]?$"]["GET"]=[&server, &calculator, &dataStatus, &transitData](std::shared_ptr<HttpServer::Response> serverResponse, std::shared_ptr<HttpServer::Request> request) {
609+
// Have a global id to match the requests in the logs
610+
static int accessibilityRequestId = 0;
605611

606612
std::string response = getFastErrorResponse(dataStatus);
607613

@@ -624,7 +630,8 @@ int main(int argc, char** argv) {
624630
parametersWithValues.push_back(std::make_pair(field.first, field.second));
625631
}
626632

627-
spdlog::info("-- calculating accessibility request --");
633+
int currentRequestId = accessibilityRequestId++;
634+
spdlog::info("-- calculating accessibility request -- {}", currentRequestId);
628635

629636
try
630637
{
@@ -636,10 +643,11 @@ int main(int argc, char** argv) {
636643
response = ResultToV2AccessibilityResponse::resultToJsonString(*accessibilityResult.get(), queryParams).dump(2);
637644
}
638645

639-
spdlog::info("-- accessibility request complete --");
646+
spdlog::info("-- accessibility request complete -- {}", currentRequestId);
640647

641648
} catch (NoRoutingFoundException &e) {
642649
response = ResultToV2AccessibilityResponse::noRoutingFoundResponse(queryParams, e.getReason()).dump(2);
650+
spdlog::info("-- accessibility request not found -- {}", currentRequestId);
643651
}
644652

645653
*serverResponse << "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: " << response.length() << "\r\n\r\n" << response;

0 commit comments

Comments
 (0)