Initial journalser
This commit is contained in:
parent
5af2177fbc
commit
8739320bb0
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "report"]
|
||||
path = report
|
||||
url = https://git.mount-mockery.de/pylib/report.git
|
6
journaliser
Executable file
6
journaliser
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
BASEPATH=$(dirname $0)
|
||||
|
||||
python3 $BASEPATH/journaliser.py $*
|
||||
|
44
journaliser.py
Normal file
44
journaliser.py
Normal file
@ -0,0 +1,44 @@
|
||||
import logging
|
||||
import report
|
||||
import subprocess
|
||||
|
||||
|
||||
logger = logging.getLogger("root")
|
||||
report.add_handler_socket(logger)
|
||||
|
||||
|
||||
class mkrecord(object):
|
||||
def __init__(self, line):
|
||||
self.line = line.strip("\n")
|
||||
self.module = line.split(" ")[4].split("[")[0]
|
||||
|
||||
if __name__ == "__main__":
|
||||
command = ['journalctl', '-fn', '500']
|
||||
# Start the process using Popen
|
||||
try:
|
||||
with subprocess.Popen(
|
||||
command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True, # Decode stdout/stderr as text using default encoding
|
||||
bufsize=1 # Use line-buffering
|
||||
) as process:
|
||||
print(f"--- Following journal output for: {' '.join(command)} ---")
|
||||
print("--- Press Ctrl+C to exit ---")
|
||||
|
||||
# Read from stdout line by line as it's generated
|
||||
for line in process.stdout:
|
||||
record = mkrecord(line)
|
||||
l = logger.getChild(record.module)
|
||||
if "crit" in record.line.lower():
|
||||
l.critical(record.line)
|
||||
elif "error" in record.line.lower():
|
||||
l.error(record.line)
|
||||
elif "warn" in record.line.lower():
|
||||
l.warning(record.line)
|
||||
elif "info" in record.line.lower():
|
||||
l.info(record.line)
|
||||
else:
|
||||
l.debug(record.line)
|
||||
except KeyboardInterrupt:
|
||||
print(" Bye...")
|
1
report
Submodule
1
report
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit c9642f1a2b57a4e9fb2d294c5f9e7bee09e8fd72
|
Loading…
x
Reference in New Issue
Block a user