Skip to content

Commit ecad98b

Browse files
committed
Add verbose to disable log
Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent 4de7425 commit ecad98b

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

examples/interactive_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def main():
1919
print("=" * 50)
2020

2121
# Connect to server
22-
server = Server("127.0.0.1", 8765)
22+
server = Server("127.0.0.1", 8765, verbose=False)
2323
print(f"✓ Server started on {server.address}\n")
2424

2525
# Wait for at least one daemon

python/sandd/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,21 @@ class Server:
137137
Args:
138138
host: Bind address (default: "0.0.0.0")
139139
port: Bind port (default: 8765)
140+
verbose: Enable logging at INFO level (default: True)
141+
Set to False to disable logs (useful for interactive sessions)
140142
141143
Example:
142144
>>> server = Server("0.0.0.0", 8765)
143145
>>> server.wait_for_daemon("daemon-1", timeout=30)
144146
>>> result = server.exec("daemon-1", "hostname")
145147
>>> print(result.stdout)
148+
149+
>>> # Disable logs for clean output, useful for interactive sessions
150+
>>> server = Server("0.0.0.0", 8765, verbose=False)
146151
"""
147152

148-
def __init__(self, host: str = "0.0.0.0", port: int = 8765):
149-
self._server = _RustServer(host, port)
153+
def __init__(self, host: str = "0.0.0.0", port: int = 8765, verbose: bool = True):
154+
self._server = _RustServer(host, port, verbose)
150155
self._host = host
151156
self._port = port
152157

server/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ pub struct Server {
3232
#[pymethods]
3333
impl Server {
3434
#[new]
35-
#[pyo3(signature = (host="0.0.0.0".to_string(), port=8765))]
36-
fn new(host: String, port: u16) -> PyResult<Self> {
37-
// Initialize logging
38-
let _ = tracing_subscriber::fmt()
39-
.with_env_filter(
40-
tracing_subscriber::EnvFilter::from_default_env()
41-
.add_directive(tracing::Level::INFO.into()),
42-
)
43-
.try_init();
35+
#[pyo3(signature = (host="0.0.0.0".to_string(), port=8765, verbose=true))]
36+
fn new(host: String, port: u16, verbose: bool) -> PyResult<Self> {
37+
// Initialize logging: INFO by default, unless verbose=False
38+
// RUST_LOG env var can override (e.g., RUST_LOG=debug)
39+
if verbose {
40+
let _ = tracing_subscriber::fmt()
41+
.with_env_filter(
42+
tracing_subscriber::EnvFilter::from_default_env()
43+
.add_directive(tracing::Level::INFO.into()),
44+
)
45+
.try_init();
46+
}
4447

4548
let runtime = Runtime::new()
4649
.map_err(|e| PyRuntimeError::new_err(format!("Failed to create runtime: {}", e)))?;

0 commit comments

Comments
 (0)