mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-20 15:46:29 +00:00
Fix log follow mode without range header (#5347)
This commit is contained in:
parent
22e50b4ace
commit
e2ada42001
@ -239,11 +239,13 @@ class APIHost(CoreSysAttributes):
|
|||||||
# return 2 lines at minimum.
|
# return 2 lines at minimum.
|
||||||
lines = max(2, lines)
|
lines = max(2, lines)
|
||||||
# entries=cursor[[:num_skip]:num_entries]
|
# entries=cursor[[:num_skip]:num_entries]
|
||||||
range_header = f"entries=:-{lines-1}:{lines}"
|
range_header = f"entries=:-{lines-1}:{'' if follow else lines}"
|
||||||
elif RANGE in request.headers:
|
elif RANGE in request.headers:
|
||||||
range_header = request.headers.get(RANGE)
|
range_header = request.headers.get(RANGE)
|
||||||
else:
|
else:
|
||||||
range_header = f"entries=:-{DEFAULT_LINES-1}:{DEFAULT_LINES}"
|
range_header = (
|
||||||
|
f"entries=:-{DEFAULT_LINES-1}:{'' if follow else DEFAULT_LINES}"
|
||||||
|
)
|
||||||
|
|
||||||
async with self.sys_host.logs.journald_logs(
|
async with self.sys_host.logs.journald_logs(
|
||||||
params=params, range_header=range_header, accept=LogFormat.JOURNAL
|
params=params, range_header=range_header, accept=LogFormat.JOURNAL
|
||||||
|
@ -7,6 +7,7 @@ from aiohttp.test_utils import TestClient
|
|||||||
from supervisor.host.const import LogFormat
|
from supervisor.host.const import LogFormat
|
||||||
|
|
||||||
DEFAULT_LOG_RANGE = "entries=:-99:100"
|
DEFAULT_LOG_RANGE = "entries=:-99:100"
|
||||||
|
DEFAULT_LOG_RANGE_FOLLOW = "entries=:-99:"
|
||||||
|
|
||||||
|
|
||||||
async def common_test_api_advanced_logs(
|
async def common_test_api_advanced_logs(
|
||||||
@ -34,7 +35,7 @@ async def common_test_api_advanced_logs(
|
|||||||
|
|
||||||
journald_logs.assert_called_once_with(
|
journald_logs.assert_called_once_with(
|
||||||
params={"SYSLOG_IDENTIFIER": syslog_identifier, "follow": ""},
|
params={"SYSLOG_IDENTIFIER": syslog_identifier, "follow": ""},
|
||||||
range_header=DEFAULT_LOG_RANGE,
|
range_header=DEFAULT_LOG_RANGE_FOLLOW,
|
||||||
accept=LogFormat.JOURNAL,
|
accept=LogFormat.JOURNAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,6 +63,6 @@ async def common_test_api_advanced_logs(
|
|||||||
"_BOOT_ID": "ccc",
|
"_BOOT_ID": "ccc",
|
||||||
"follow": "",
|
"follow": "",
|
||||||
},
|
},
|
||||||
range_header=DEFAULT_LOG_RANGE,
|
range_header=DEFAULT_LOG_RANGE_FOLLOW,
|
||||||
accept=LogFormat.JOURNAL,
|
accept=LogFormat.JOURNAL,
|
||||||
)
|
)
|
||||||
|
@ -15,6 +15,7 @@ from tests.dbus_service_mocks.base import DBusServiceMock
|
|||||||
from tests.dbus_service_mocks.systemd import Systemd as SystemdService
|
from tests.dbus_service_mocks.systemd import Systemd as SystemdService
|
||||||
|
|
||||||
DEFAULT_RANGE = "entries=:-99:100"
|
DEFAULT_RANGE = "entries=:-99:100"
|
||||||
|
DEFAULT_RANGE_FOLLOW = "entries=:-99:"
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
|
|
||||||
@ -233,7 +234,7 @@ async def test_advanced_logs(
|
|||||||
"SYSLOG_IDENTIFIER": coresys.host.logs.default_identifiers,
|
"SYSLOG_IDENTIFIER": coresys.host.logs.default_identifiers,
|
||||||
"follow": "",
|
"follow": "",
|
||||||
},
|
},
|
||||||
range_header=DEFAULT_RANGE,
|
range_header=DEFAULT_RANGE_FOLLOW,
|
||||||
accept=LogFormat.JOURNAL,
|
accept=LogFormat.JOURNAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user