Skip to content

Commit d4123c8

Browse files
committed
accept int in log level env var
1 parent 41d9759 commit d4123c8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/torchrunx/utils/logs.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ def default_handlers(hostnames: list[str], workers_per_host: list[int]) -> list[
6363
hostname, local_rank).
6464
"""
6565
log_dir = Path(os.environ.get("TORCHRUNX_LOG_DIR", "torchrunx_logs"))
66-
file_log_level = logging._nameToLevel[os.environ.get("TORCHRUNX_LOG_LEVEL", "INFO")] # noqa: SLF001
66+
67+
file_log_level = os.environ.get("TORCHRUNX_LOG_LEVEL", "INFO")
68+
if file_log_level.isdigit():
69+
file_log_level = int(file_log_level)
70+
elif file_log_level in logging._nameToLevel: # noqa: SLF001
71+
file_log_level = logging._nameToLevel[file_log_level] # noqa: SLF001
72+
else:
73+
msg = (
74+
f"Invalid value for $TORCHRUNX_LOG_LEVEL: {file_log_level}. "
75+
f"Should be a positive integer or any of: {', '.join(logging._nameToLevel.keys())}." # noqa: SLF001
76+
)
77+
raise ValueError(msg)
6778

6879
return [
6980
RedirectHandler(hostname=hostnames[0], local_rank=None),

0 commit comments

Comments
 (0)