diff --git a/diracx-db/src/diracx/db/os/pilot_logs.py b/diracx-db/src/diracx/db/os/pilot_logs.py index e4080268..de156266 100644 --- a/diracx-db/src/diracx/db/os/pilot_logs.py +++ b/diracx-db/src/diracx/db/os/pilot_logs.py @@ -6,6 +6,7 @@ class PilotLogsDB(BaseOSDB): fields = { "PilotStamp": {"type": "keyword"}, + "PilotID": {"type": "long"}, "LineNumber": {"type": "long"}, "Message": {"type": "text"}, "VO": {"type": "keyword"}, diff --git a/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py b/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py index 418f8d39..b8eec760 100644 --- a/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py +++ b/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py @@ -51,10 +51,28 @@ async def send_message( docs.append( { "PilotStamp": data.pilot_stamp, + "PilotID": pilot_id, "VO": data.vo, "LineNumber": line.line_no, "Message": line.line, } ) await pilot_logs_db.bulk_insert(pilot_logs_db.index_name(pilot_id), docs) - return data + return pilot_id + + +@router.get("/logs") +async def get_logs( + pilot_id: int, + db: PilotLogsDB, + check_permissions: CheckPilotLogsPolicyCallable, +): + logger.warning(f"Retrieving message for pilot ID '{pilot_id}'") + await check_permissions(action=ActionType.QUERY, pilot_db=db) + + result = await db.search( + ["Message"], + [{"parameter": "PilotID", "operator": "eq"} | {"value": pilot_id}], + [{"parameter": "LineNumber", "direction": "asc"}], + ) + return result