Skip to content

Commit e75cace

Browse files
committed
logging: add to create inquirer
1 parent 13f14c3 commit e75cace

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/warnet/graph.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def custom_graph(
3434
fork_observer: bool,
3535
fork_obs_query_interval: int,
3636
caddy: bool,
37+
logging: bool,
3738
):
3839
datadir.mkdir(parents=False, exist_ok=False)
3940
# Generate network.yaml
@@ -79,10 +80,13 @@ def custom_graph(
7980
# Generate node-defaults.yaml
8081
default_yaml_path = files("resources.networks").joinpath("node-defaults.yaml")
8182
with open(str(default_yaml_path)) as f:
82-
defaults_yaml_content = f.read()
83+
defaults_yaml_content = yaml.safe_load(f)
84+
85+
# Configure logging
86+
defaults_yaml_content["collectLogs"] = logging
8387

8488
with open(os.path.join(datadir, "node-defaults.yaml"), "w") as f:
85-
f.write(defaults_yaml_content)
89+
yaml.dump(defaults_yaml_content, f, default_flow_style=False, sort_keys=False)
8690

8791
click.echo(
8892
f"Project '{datadir}' has been created with 'network.yaml' and 'node-defaults.yaml'."
@@ -175,6 +179,15 @@ def inquirer_create_network(project_path: Path):
175179
type=int,
176180
default=20,
177181
)
182+
183+
logging = click.prompt(
184+
click.style(
185+
"\nWould you like to enable grafana logging on the network?", fg="blue", bold=True
186+
),
187+
type=bool,
188+
default=False,
189+
)
190+
caddy = fork_observer | logging
178191
custom_network_path = project_path / "networks" / net_answers["network_name"]
179192
click.secho("\nGenerating custom network...", fg="yellow", bold=True)
180193
custom_graph(
@@ -184,7 +197,8 @@ def inquirer_create_network(project_path: Path):
184197
custom_network_path,
185198
fork_observer,
186199
fork_observer_query_interval,
187-
fork_observer, # This enables caddy whenever fork-observer is enabled
200+
caddy,
201+
logging,
188202
)
189203
return custom_network_path
190204

test/graph_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def directory_exists(self):
4040
self.sut.sendline("")
4141
self.sut.expect("seconds", timeout=10)
4242
self.sut.sendline("")
43+
self.sut.expect("enable grafana", timeout=10)
44+
self.sut.sendline("")
4345
self.sut.expect("successfully", timeout=50)
4446

4547

0 commit comments

Comments
 (0)