Skip to content

Commit eddb661

Browse files
committed
refactor: logging
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent 03d33b6 commit eddb661

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

gpustack_runtime/deployer/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def is_supported() -> bool:
273273
supported = client.ping()
274274
except docker.errors.APIError:
275275
if logger.isEnabledFor(logging.DEBUG):
276-
logger.exception("Docker ping failed")
276+
logger.exception("Failed to connect to Docker API server")
277277

278278
return supported
279279

gpustack_runtime/deployer/kuberentes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ def is_supported() -> bool:
280280
version_api = kubernetes.client.VersionApi(client)
281281
version_info = version_api.get_code()
282282
supported = version_info is not None
283-
except kubernetes.client.exceptions.ApiException:
284-
if logger.isEnabledFor(logging.DEBUG):
285-
logger.exception("Failed to get Kubernetes version")
286-
except urllib3.exceptions.MaxRetryError:
283+
except (
284+
urllib3.exceptions.MaxRetryError,
285+
kubernetes.client.exceptions.ApiException,
286+
):
287287
if logger.isEnabledFor(logging.DEBUG):
288288
logger.exception("Failed to connect to Kubernetes API server")
289289

gpustack_runtime/detector/ascend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .__utils__ import PCIDevice, get_brief_version, get_pci_devices, get_utilization
1111

1212
logger = logging.getLogger(__name__)
13+
slogger = logger.getChild("internal")
1314

1415

1516
class AscendDetector(Detector):
@@ -261,8 +262,8 @@ def _get_device_roce_network_info(
261262
pydcmi.DCMI_PORT_TYPE_ROCE_PORT,
262263
)
263264
except pydcmi.DCMIError:
264-
if logger.isEnabledFor(logging.DEBUG):
265-
logger.exception("Failed to get device roce network info")
265+
if slogger.isEnabledFor(logging.DEBUG):
266+
slogger.exception("Failed to get device roce network info")
266267

267268
return ip, mask, gateway
268269

@@ -288,8 +289,8 @@ def _get_device_virtual_info(
288289
c_vdev_query_stru,
289290
)
290291
except pydcmi.DCMIError:
291-
if logger.isEnabledFor(logging.DEBUG):
292-
logger.exception("Failed to get device virtual info")
292+
if slogger.isEnabledFor(logging.DEBUG):
293+
slogger.exception("Failed to get device virtual info")
293294
else:
294295
return c_vdev_query_stru
295296

gpustack_runtime/logging.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ def _parse_module_levels(level_str: str) -> dict[str, int]:
2727
Parse the GPUSTACK_RUNTIME_LOG_LEVEL environment variable to determine module-specific log levels.
2828
2929
Examples:
30-
- "DEBUG" # All modules at DEBUG
31-
- "runtime.module_a:DEBUG" # Only module_a module at DEBUG, other modules at INFO
32-
- "module_a:DEBUG" # Same as above
33-
- "runtime.module_a:DEBUG;runtime.module_b:INFO" # Multiple modules
34-
- "ERROR;runtime.module_a:DEBUG" # All modules at ERROR, only module_a module at DEBUG
30+
- "DEBUG" # All modules at DEBUG
31+
- "gpustack_runtime.module_a:DEBUG" # Only module_a module at DEBUG, other modules at INFO
32+
- "module_a:DEBUG" # Same as above
33+
- "module_a=DEBUG" # Using '=' instead of ':'
34+
- "gpustack_runtime.module_a:DEBUG;gpustack_runtime.module_b:INFO" # Multiple modules
35+
- "ERROR;runtime.module_a:DEBUG" # All modules at ERROR, only module_a module at DEBUG
3536
3637
"""
3738
module_levels: dict[str, int] = {} # {"module_name": log_level}
@@ -48,14 +49,16 @@ def _parse_module_levels(level_str: str) -> dict[str, int]:
4849
module = ""
4950
level = ""
5051
if ":" in p:
51-
module, level = p.split(":")
52+
module, level = p.split(":", 1)
53+
elif "=" in p:
54+
module, level = p.split("=", 1)
5255

5356
level = level.upper()
5457
if level not in levels:
5558
continue
5659

5760
module = module.strip()
58-
module = module.replace("runtime.", "")
61+
module = module.replace(f"{__package__}.", "")
5962
module = module.replace("/", ".").strip(".")
6063

6164
module_levels[module] = getattr(logging, level)

0 commit comments

Comments
 (0)