-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logging output to the General Debug tab
- Loading branch information
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
from logging.handlers import MemoryHandler | ||
|
||
from aiohttp import web | ||
|
||
from tribler.core.restapi.rest_endpoint import RESTEndpoint, RESTResponse | ||
|
||
|
||
class LoggingEndpoint(RESTEndpoint): | ||
""" | ||
This endpoint allows retrieval of the logs. | ||
""" | ||
|
||
path = '/api/logging' | ||
|
||
def __init__(self) -> None: | ||
""" | ||
Create a new logging endpoint. | ||
""" | ||
super().__init__() | ||
|
||
self.base_handler = logging.getLogger().handlers[0] | ||
|
||
self.memory_logger = MemoryHandler(100000) | ||
logging.getLogger().addHandler(self.memory_logger) | ||
|
||
self.app.add_routes([web.get("", self.get_logs)]) | ||
|
||
def get_logs(self, request: web.Request) -> RESTResponse: | ||
""" | ||
Return the most recent logs. | ||
""" | ||
return RESTResponse("\n".join(self.base_handler.format(r) for r in self.memory_logger.buffer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters