mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-12-04 12:38:19 +01:00
write log since last boot to file
This commit is contained in:
parent
4ca441bba3
commit
f5c242d7c8
1 changed files with 12 additions and 6 deletions
|
@ -148,19 +148,25 @@ class SystemController:
|
||||||
if logtime == "b":
|
if logtime == "b":
|
||||||
if systemd_available:
|
if systemd_available:
|
||||||
#os.system('journalctl -b -u craftbeerpi.service --output cat > {}'.format(fullname))
|
#os.system('journalctl -b -u craftbeerpi.service --output cat > {}'.format(fullname))
|
||||||
j = journal.Reader()
|
b = journal.Reader()
|
||||||
j.add_match(_TRANSPORT="kernel")
|
b.add_match(_TRANSPORT="kernel")
|
||||||
result=[]
|
result=[]
|
||||||
for entry in j:
|
for entry in b:
|
||||||
message=entry['MESSAGE']
|
message=entry['MESSAGE']
|
||||||
if message.find("Booting") != -1:
|
if message.find("Booting") != -1:
|
||||||
result.append(entry['__REALTIME_TIMESTAMP'])
|
result.append(entry['__REALTIME_TIMESTAMP'])
|
||||||
|
j = journal.Reader()
|
||||||
j.add_match(_SYSTEMD_UNIT="craftbeerpi.service")
|
j.add_match(_SYSTEMD_UNIT="craftbeerpi.service")
|
||||||
j.seek_realtime(result[-1])
|
j.seek_realtime(result[-1])
|
||||||
|
result=[]
|
||||||
for entry in j:
|
for entry in j:
|
||||||
timestamp=entry['__REALTIME_TIMESTAMP']
|
result.append(entry['MESSAGE'])
|
||||||
message=entry['MESSAGE']
|
try:
|
||||||
print(message)
|
with open(fullname, 'w') as f:
|
||||||
|
for line in result:
|
||||||
|
f.write(f"{line}\n")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if systemd_available:
|
if systemd_available:
|
||||||
|
|
Loading…
Reference in a new issue