adds journalctl arg '--output cat' (log exports),

because cbpi already writes timestamps into the logs
and we dont need two timestamps when exporting.
This commit also reverts to using the same formatter for all logHandlers.
This commit is contained in:
prash3r 2022-09-14 13:54:58 +02:00
parent c56d7ccc51
commit f924e1a683
2 changed files with 2 additions and 12 deletions

View file

@ -17,7 +17,6 @@ from importlib_metadata import metadata
from tabulate import tabulate from tabulate import tabulate
from PyInquirer import prompt, print_json from PyInquirer import prompt, print_json
import platform import platform
import subprocess
class CraftBeerPiCli(): class CraftBeerPiCli():
def __init__(self, config) -> None: def __init__(self, config) -> None:
@ -239,15 +238,6 @@ def main(context, config_folder_path, logs_folder_path, debug_log_level):
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s') formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s')
logging.basicConfig(format=formatter,level=debug_log_level, stream=logging.StreamHandler()) logging.basicConfig(format=formatter,level=debug_log_level, stream=logging.StreamHandler())
logger = logging.getLogger() logger = logging.getLogger()
try:
result = subprocess.run(['journalctl', '--since', '2 hours ago', '-u', 'craftbeerpi.service' ], stdout=subprocess.PIPE)
# journalctl is present, we assume we are running in production.
# We therefore omit the timestamp from the stdout log handler formatter because timestamps are added to the logs by journalctl anyway
logger.handlers[0].setFormatter('%(levelname)s - %(name)s - %(message)s')
except:
# journalctl command seems to not be present.
# We assume we are in the dev container and keep writing timestampts to stdout for vscode terminal output
logger.warning("journalctl command error - assuming dev container execution and writing timestamps to stdout")
try: try:
if not os.path.isdir(logs_folder_path): if not os.path.isdir(logs_folder_path):
logger.info(f"logs folder '{logs_folder_path}' doesnt exist and we are trying to create it") logger.info(f"logs folder '{logs_folder_path}' doesnt exist and we are trying to create it")

View file

@ -56,9 +56,9 @@ class SystemController:
output_filename="cbpi4_log.zip" output_filename="cbpi4_log.zip"
if logtime == "b": if logtime == "b":
os.system('journalctl -b -u craftbeerpi.service > {}'.format(fullname)) os.system('journalctl -b -u craftbeerpi.service --output cat > {}'.format(fullname))
else: else:
os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service > {}'.format(logtime, fullname)) os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service --output cat > {}'.format(logtime, fullname))
os.system('cbpi plugins > {}'.format(fullpluginname)) os.system('cbpi plugins > {}'.format(fullpluginname))