Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log routes when the router is populated #609

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Robyn accepts dictionaries to build a response for the route:
async def dictionary(request):
return {
"status_code": 200,
"body": "This is a regular response",
"description": "This is a regular response",
"type": "text",
"headers": {"Header": "header_value"},
}
Expand Down
5 changes: 5 additions & 0 deletions robyn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def add_route(
}
route_type = http_methods[route_type]

routes = self.router.get_routes()

for route in routes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do the for loop here, this function runs for every route separately and has the endpoint and method as input parameters.

Copy link
Contributor Author

@carlosm27 carlosm27 Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misunderstand when you said to write the logs in add_route method. I tried this without using a for loop, but it shows one route when running the base_routes.py file. What I'm trying to do is that it shows all the routes in the list of routes.

if len(routes) > 2:
            logger.info(f"Logging endpoint: method={routes[0][0]}, route={routes[0][1]}")

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Sorry, yes I misunderstand.

logger.info(f"Logging endpoint: method={route_type}, route={endpoint}")

image

logger.info(f"Logging endpoint: method: {route[0]}, route: {route[1]}")

return self.router.add_route(
route_type, endpoint, handler, is_const, self.exception_handler
)
Expand Down
Loading