-
Notifications
You must be signed in to change notification settings - Fork 179
/
logs.py
57 lines (51 loc) · 1.88 KB
/
logs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from fastapi import APIRouter, Query, Response
from typing import Annotated, Dict
from opentrons.system import log_control
from robot_server.service.legacy.models.logs import LogIdentifier, LogFormat
router = APIRouter()
IDENTIFIER_TO_SYSLOG_ID: Dict[LogIdentifier, str] = {
LogIdentifier.api: "opentrons-api",
LogIdentifier.serial: log_control.SERIAL_SPECIAL,
LogIdentifier.server: "uvicorn",
LogIdentifier.api_server: "opentrons-robot-server",
LogIdentifier.update_server: "opentrons-update-server",
LogIdentifier.touchscreen: "opentrons-robot-app",
LogIdentifier.can: "opentrons-api-serial-can",
}
@router.get(
path="/logs/{log_identifier}",
summary="Get troubleshooting logs",
description=(
"Get the robot's troubleshooting logs."
"\n\n"
"If you want the list of steps executed in a protocol,"
' like "aspirated 5 µL from well A1...", you probably want the'
" *protocol analysis commands* (`GET /protocols/{id}/analyses/{id}`)"
" or *run commands* (`GET /runs/{id}/commands`) instead."
),
)
async def get_logs(
log_identifier: LogIdentifier,
response: Response,
format: Annotated[LogFormat, Query(title="Log format type")] = LogFormat.text,
records: Annotated[
int,
Query(
title="Number of records to retrieve",
gt=0,
le=log_control.MAX_RECORDS,
),
] = log_control.DEFAULT_RECORDS,
) -> Response:
syslog_id = IDENTIFIER_TO_SYSLOG_ID[log_identifier]
modes = {
LogFormat.json: ("json", "application/json"),
LogFormat.text: ("short-precise", "text/plain"),
}
format_type, media_type = modes[format]
output = await log_control.get_records_dumb(syslog_id, records, format_type)
return Response(
content=output.decode("utf-8"),
media_type=media_type,
headers=dict(response.headers),
)