Skip to content

Commit 6550243

Browse files
szachovyCopilot
authored andcommitted
Add --debug flag and structured logging
Add --debug flag to superset-cluster shell script that sets SUPERSET_CLUSTER_DEBUG=1. Add configure_logging() that sets DEBUG level when the env var is set. Replace print() with logger calls in initialize.py. Enhance log_remote_command_execution decorator to emit raw stdout/stderr at DEBUG level while keeping INFO concise. Closes #67 Closes #53 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a459eb7 commit 6550243

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
* SQL Lab query row limits, timeout caps, and validation timeout. (#81)
2222
* Superset metastore and explore form data caching via Redis. (#79)
2323

24+
### Added
25+
26+
* `--debug` flag and structured logging with `configure_logging()`. (#67)
27+
2428
### Changed
2529

2630
* Completed [ARCHITECTURE.md](./docs/ARCHITECTURE.md) (#93)

src/initialize.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import functools
6060
import ipaddress
6161
import itertools
62+
import logging
63+
import os
6264
import re
6365
import socket
6466

@@ -67,6 +69,19 @@
6769
import remote
6870

6971

72+
def configure_logging() -> None:
73+
level = logging.DEBUG if os.environ.get('SUPERSET_CLUSTER_DEBUG') else logging.INFO
74+
logging.basicConfig(
75+
level=level,
76+
format='%(asctime)s [%(levelname)s] [%(name)s] %(message)s'
77+
)
78+
logging.getLogger('paramiko').setLevel(logging.WARNING)
79+
logging.getLogger('urllib3').setLevel(logging.WARNING)
80+
81+
82+
logger = logging.getLogger(__name__)
83+
84+
7085
@decorators.Overlay.run_all_methods # type: ignore[arg-type]
7186
class ArgumentParser:
7287
def validate_virtual_ip_address(self) -> None:
@@ -299,6 +314,7 @@ def start_cluster(self) -> None:
299314

300315
if __name__ == "__main__":
301316
if len(sys.argv) != 6:
302-
print("Invalid form of arguments provided")
317+
logger.error("Invalid form of arguments provided")
303318
sys.exit(1)
319+
configure_logging()
304320
Controller().start_cluster()

src/remote.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ def wrapper(*args, **kwargs):
9494
result = func(*args, **kwargs)
9595
if result["output"]:
9696
logger.info(
97-
"[Node: %s] Command: %s - Output:\n%s",
97+
"[Node: %s] Command: %s completed",
98+
getattr(self, 'node', 'UnknownNode'),
99+
command
100+
)
101+
logger.debug(
102+
"[Node: %s] Command: %s - stdout:\n%s",
98103
getattr(self, 'node', 'UnknownNode'),
99104
command,
100105
result["output"]
@@ -106,6 +111,12 @@ def wrapper(*args, **kwargs):
106111
command,
107112
result["error"]
108113
)
114+
logger.debug(
115+
"[Node: %s] Command: %s - stderr:\n%s",
116+
getattr(self, "node", "UnknownNode"),
117+
command,
118+
result["error"]
119+
)
109120
return result
110121
return wrapper
111122

superset-cluster

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ display_help() {
2020
echo " --virtual-network-mask <mask> Network mask for the virtual network gateway."
2121
echo " Example: --virtual-network-mask 24"
2222
echo
23+
echo " --debug Enable debug-level logging."
24+
echo
2325
echo " -h, --help Show this help message and exit."
2426
echo
2527
echo "Example:"
@@ -59,6 +61,9 @@ parse_arguments() {
5961
display_help
6062
exit 0
6163
;;
64+
--debug)
65+
export SUPERSET_CLUSTER_DEBUG=1
66+
;;
6267
*)
6368
echo "Unknown option: $1"
6469
display_help

0 commit comments

Comments
 (0)