Skip to content

Commit

Permalink
add proper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Jun 12, 2024
1 parent 24c02db commit 9449ab8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion scripts/docker_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def kill_container_by_id(container_identifier : str) -> None:
if container_identifier is None:
return

subprocess.run(["docker", "kill", container_identifier], check=True)
cmd = ["docker", "kill", container_identifier]
print(' '.join(cmd))
subprocess.run(cmd, check=True)

@staticmethod
def run_container(sniffer_path: str, image_name: str, sim_config: str, mode: SimMode):
Expand Down
21 changes: 18 additions & 3 deletions scripts/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
import os
import sys
import time
import logging
import datetime
from typing import Optional
from pathlib import Path

from argparse import ArgumentParser, RawTextHelpFormatter
from configurator import configure
from command import SimCommand
from docker_wrapper import DockerWrapper
from model import SimModel

REPOSITORY_DIR = Path(__file__).parent.parent.absolute()
VEHICLES_DIR = f"{REPOSITORY_DIR}/configs/vehicles"
REPO_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
VEHICLES_DIR = os.path.join(REPO_DIR, "configs", "vehicles")
BINARY_OUTPUT_PATH = os.path.join(REPO_DIR, "firmware.bin")
LOG_FILENAME = f"log_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.log"
LOG_PATH = os.path.join(REPO_DIR, "logs", LOG_FILENAME)

COMMANDS = [
SimCommand(name="build", alias='b', mode=None, info="Build the Docker image"),
SimCommand(name="kill", alias='', mode=None, info="Kill the running Docker container"),
Expand Down Expand Up @@ -102,6 +107,16 @@ def process(self, command: Optional[str]) -> None:


def main():
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
filename=LOG_PATH,
filemode='w')
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger().addHandler(console)

parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)

command_help = f'{"Command":<36} {"Alias":<10} {"Info"}\n'
Expand Down

0 comments on commit 9449ab8

Please sign in to comment.