Improve logic for the get_logs() method. Add rascsi-ctrlboard service. (#714)

This commit is contained in:
Daniel Markstedt 2022-02-28 09:49:48 -08:00 committed by GitHub
parent 0e8d89e827
commit da02eccb2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 20 deletions

View File

@ -149,21 +149,20 @@ class SysCmds:
def get_logs(lines, scope):
"""
Takes (int) lines and (str) scope.
If scope is a None equivalent, all syslogs are returned.
Returns either the decoded log output, or the stderr output of journalctl.
"""
if scope != "all":
line_param = []
scope_param = []
if lines:
line_param = ["-n", lines]
if scope:
scope_param = ["-u", scope]
process = run(
["journalctl", "-n", lines, "-u", scope],
["journalctl"] + line_param + scope_param,
capture_output=True,
check=True,
)
else:
process = run(
["journalctl", "-n", lines],
capture_output=True,
check=True,
)
if process.returncode == 0:
return process.returncode, process.stdout.decode("utf-8")

View File

@ -604,17 +604,20 @@
<input name="lines" type="number" value="200" min="1" size="4">
<label for="scope">{{ _("Scope:") }}</label>
<select name="scope">
<option value="all">
all
<option value="">
{{ _("All logs") }}
</option>
<option value="rascsi">
rascsi.service
rascsi
</option>
<option value="rascsi-web">
rascsi-web.service
rascsi-web
</option>
<option value="rascsi-oled">
rascsi-oled.service
rascsi-oled
</option>
<option value="rascsi-ctrlboard">
rascsi-ctrlboard
</option>
</select>
<input type="submit" value="{{ _("Show Logs") }}">

View File

@ -435,8 +435,8 @@ def show_logs():
"""
Displays system logs
"""
lines = request.form.get("lines") or "200"
scope = request.form.get("scope") or "all"
lines = request.form.get("lines")
scope = request.form.get("scope")
returncode, logs = sys_cmd.get_logs(lines, scope)
if returncode == 0: