From f3e797694b722c7a16054f773fc09f91720e95be Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 30 Jun 2021 08:07:11 -0400 Subject: [PATCH] Agent: Format config log messages so they are readable --- monkey/infection_monkey/control.py | 7 ++++--- monkey/infection_monkey/main.py | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/monkey/infection_monkey/control.py b/monkey/infection_monkey/control.py index 6fdd585b2..feff589c1 100644 --- a/monkey/infection_monkey/control.py +++ b/monkey/infection_monkey/control.py @@ -1,6 +1,7 @@ import json import logging import platform +from pprint import pformat from socket import gethostname from urllib.parse import urljoin @@ -206,10 +207,10 @@ class ControlClient(object): try: unknown_variables = WormConfiguration.from_kv(reply.json().get("config")) - LOG.info( - "New configuration was loaded from server: %r" - % (WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict()),) + formatted_config = pformat( + WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict()) ) + LOG.info(f"New configuration was loaded from server:\n{formatted_config}") except Exception as exc: # we don't continue with default conf here because it might be dangerous LOG.error( diff --git a/monkey/infection_monkey/main.py b/monkey/infection_monkey/main.py index 9bdece16d..905c04ff8 100644 --- a/monkey/infection_monkey/main.py +++ b/monkey/infection_monkey/main.py @@ -6,6 +6,7 @@ import os import sys import traceback from multiprocessing import freeze_support +from pprint import pformat # dummy import for pyinstaller # noinspection PyUnresolvedReferences @@ -76,10 +77,8 @@ def main(): "default" % (config_file,) ) - print( - "Loaded Configuration: %r" - % WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict()) - ) + formatted_config = pformat(WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict())) + print(f"Loaded Configuration:\n{formatted_config}") # Make sure we're not in a machine that has the kill file kill_path = (