#2560 - Addressing the sys_log bug that could occur when scripts run across two time intervals. Additional updates to network_simulator notebook so that sys_log works in production mode
This commit is contained in:
@@ -27,10 +27,10 @@ class LogLevel(IntEnum):
|
||||
|
||||
class _SimOutput:
|
||||
def __init__(self):
|
||||
date_str = datetime.now().strftime("%Y-%m-%d")
|
||||
time_str = datetime.now().strftime("%H-%M-%S")
|
||||
self.date_str = datetime.now().strftime("%Y-%m-%d")
|
||||
self.time_str = datetime.now().strftime("%H-%M-%S")
|
||||
|
||||
path = PRIMAITE_PATHS.user_sessions_path / date_str / time_str
|
||||
path = PRIMAITE_PATHS.user_sessions_path / self.date_str / self.time_str
|
||||
|
||||
self._path = path
|
||||
self._save_pcap_logs: bool = False
|
||||
@@ -41,17 +41,15 @@ class _SimOutput:
|
||||
@property
|
||||
def path(self) -> Path:
|
||||
if is_dev_mode():
|
||||
date_str = datetime.now().strftime("%Y-%m-%d")
|
||||
time_str = datetime.now().strftime("%H-%M-%S")
|
||||
# if dev mode is enabled, if output dir is not set, print to primaite repo root
|
||||
path: Path = _PRIMAITE_ROOT.parent.parent / "sessions" / date_str / time_str / "simulation_output"
|
||||
path: Path = _PRIMAITE_ROOT.parent.parent / "sessions" / self.date_str / self.time_str / "simulation_output"
|
||||
# otherwise print to output dir
|
||||
if PRIMAITE_CONFIG["developer_mode"]["output_dir"]:
|
||||
path: Path = (
|
||||
Path(PRIMAITE_CONFIG["developer_mode"]["output_dir"])
|
||||
/ "sessions"
|
||||
/ date_str
|
||||
/ time_str
|
||||
/ self.date_str
|
||||
/ self.time_str
|
||||
/ "simulation_output"
|
||||
)
|
||||
self._path = path
|
||||
|
||||
@@ -148,6 +148,15 @@
|
||||
"my_server.file_system.create_file(\"favicon.ico\", file_type=FileType.PNG)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"my_server.sys_log.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"source": [
|
||||
"# PrimAITE Router Simulation Demo\n",
|
||||
"\n",
|
||||
"This demo uses the ARCD Use Case 2 Network (seen below) to demonstrate the capabilities of the Network simulator in PrimAITE."
|
||||
"This demo uses a modified version ARCD Use Case 2 Network (seen below) to demonstrate the capabilities of the Network simulator in PrimAITE."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ import yaml
|
||||
|
||||
from primaite import getLogger, PRIMAITE_PATHS
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from primaite.simulator import LogLevel, SIM_OUTPUT
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import NIC
|
||||
@@ -289,6 +290,10 @@ def arcd_uc2_network() -> Network:
|
||||
|
||||
def network_simulator_demo_example() -> Network:
|
||||
"""Returns a lightly modified version of the ARCD UC2 Network."""
|
||||
# Ensure that sys_log will be viewable for demo
|
||||
SIM_OUTPUT.sys_log_level = LogLevel.DEBUG
|
||||
SIM_OUTPUT.save_sys_logs = True
|
||||
|
||||
network = arcd_uc2_network()
|
||||
network.get_node_by_hostname("router_1").route_table.add_route(
|
||||
address="192.168.10.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2"
|
||||
|
||||
@@ -52,7 +52,8 @@ class SysLog:
|
||||
file_handler.setFormatter(logging.Formatter(log_format))
|
||||
|
||||
self.logger = logging.getLogger(f"{self.hostname}_sys_log")
|
||||
self.logger.handlers.clear() # clear handlers
|
||||
for handler in self.logger.handlers:
|
||||
self.logger.removeHandler(handler)
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
self.logger.addHandler(file_handler)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user