Skip to content

Commit 1df1ef5

Browse files
authored
Merge pull request #178 from thorinaboenke/177_fix_background_command_logging
json und metadata logging for background commands
2 parents aeb0114 + 4cf3e26 commit 1df1ef5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/attackmate/executors/baseexecutor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ def run(self, command: BaseCommand) -> Result:
8181
self.logger.debug(f"Template-Command: '{command.cmd}'")
8282
if command.background:
8383
# Background commands always return Result(None,None)
84+
time_of_execution = datetime.now().isoformat()
85+
self.log_json(self.json_logger, command, time_of_execution)
8486
result = self.exec_background(self.substitute_template_vars(command, self.substitute_cmd_vars))
8587
else:
8688
result = self.exec(self.substitute_template_vars(command, self.substitute_cmd_vars))
8789

8890
return result
8991

90-
9192
def log_command(self, command):
9293
"""Log starting-status of the command"""
9394
self.logger.info(f"Executing '{command}'")

src/attackmate/executors/features/background.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from attackmate.schemas.base import BaseCommand
23
from attackmate.processmanager import ProcessManager
34
from attackmate.result import Result
@@ -30,7 +31,8 @@ def _create_queue(self) -> Optional[Queue]:
3031

3132
def exec_background(self, command: BaseCommand) -> Result:
3233
self.logger.info(f'Run in background: {getattr(command, "type", "")}({command.cmd})')
33-
34+
if command.metadata:
35+
self.logger.info(f'Metadata: {json.dumps(command.metadata)}')
3436
queue = self._create_queue()
3537

3638
if queue:

0 commit comments

Comments
 (0)