Skip to content

Commit

Permalink
write log since last boot to file
Browse files Browse the repository at this point in the history
  • Loading branch information
avollkopf committed May 2, 2024
1 parent 4ca441b commit f5c242d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cbpi/controller/system_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,25 @@ async def downloadlog(self, logtime):
if logtime == "b":
if systemd_available:
#os.system('journalctl -b -u craftbeerpi.service --output cat > {}'.format(fullname))
j = journal.Reader()
j.add_match(_TRANSPORT="kernel")
b = journal.Reader()
b.add_match(_TRANSPORT="kernel")
result=[]
for entry in j:
for entry in b:
message=entry['MESSAGE']
if message.find("Booting") != -1:
result.append(entry['__REALTIME_TIMESTAMP'])
j = journal.Reader()
j.add_match(_SYSTEMD_UNIT="craftbeerpi.service")
j.seek_realtime(result[-1])
result=[]
for entry in j:
timestamp=entry['__REALTIME_TIMESTAMP']
message=entry['MESSAGE']
print(message)
result.append(entry['MESSAGE'])
try:
with open(fullname, 'w') as f:
for line in result:
f.write(f"{line}\n")
except Exception as e:
logging.error(e)

else:
if systemd_available:
Expand Down

0 comments on commit f5c242d

Please sign in to comment.