Skip to content

Commit

Permalink
chore: make noisy API route log at the TRACE level
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemDoum committed Jan 11, 2024
1 parent 9417de3 commit 4ee817a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions neo4j-app/neo4j_app/app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from neo4j_app.app.doc import TASKS_TAG
from neo4j_app.core.objects import TaskJob, TaskSearch
from neo4j_app.core.utils.logging import log_elapsed_time_cm
from neo4j_app.core.utils.logging import TRACE, log_elapsed_time_cm
from neo4j_app.icij_worker import (
Task,
TaskError,
Expand Down Expand Up @@ -99,9 +99,7 @@ async def _get_task_errors(task_id: str, project: str) -> List[TaskError]:
@router.post("/tasks/search", response_model=List[Task])
async def _search_tasks(project: str, search: TaskSearch) -> List[Task]:
task_manager = lifespan_task_manager()
with log_elapsed_time_cm(
logger, logging.INFO, "Searched tasks in {elapsed_time} !"
):
with log_elapsed_time_cm(logger, TRACE, "Searched tasks in {elapsed_time} !"):
tasks = await task_manager.get_tasks(
project=project, task_type=search.type, status=search.status
)
Expand Down
7 changes: 7 additions & 0 deletions neo4j-app/neo4j_app/core/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
from functools import wraps
from typing import Optional, final

TRACE = 5
logging.TRACE = TRACE
logging.addLevelName(logging.TRACE, "TRACE")
logging.Logger.trace = lambda inst, msg, *args, **kwargs: inst.log(
logging.TRACE, msg, *args, **kwargs
)


class DifferedLoggingMessage:
def __init__(self, fn, *args, **kwargs):
Expand Down

0 comments on commit 4ee817a

Please sign in to comment.