Skip to content

Commit 49d2678

Browse files
authored
Log fix (#243)
* Fixed log management for Python 3.13+.
1 parent de63efc commit 49d2678

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ default-members = [
2929
]
3030

3131
[workspace.package]
32-
version = "1.12.1"
32+
version = "1.12.2"
3333
edition = "2021"
3434
authors = ["Ivan Kudriavtsev <[email protected]>"]
3535
description = "Savant Rust core functions library"

savant_python/python/savant_rs/py/log/log_utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,18 @@ def check_func_conflict(func, name, original_name, is_func, target):
161161
),
162162
)
163163

164-
logging._acquireLock()
164+
if '_acquireLock' in dir(logging):
165+
logging._acquireLock()
166+
165167
try:
166-
registered_num = logging.getLevelName(level_name)
168+
# Check if level name is already registered using _nameToLevel (Python 3.2+)
169+
# This is the correct way to check registration, and avoids getLevelName deprecation
170+
# _nameToLevel is available since Python 3.2, and this project requires >= 3.8
171+
registered_num = logging._nameToLevel.get(level_name)
167172
logger_class = logging.getLoggerClass()
168173
logger_adapter = logging.LoggerAdapter
169174

170-
if registered_num != 'Level ' + level_name:
175+
if registered_num is not None:
171176
check_conflict(
172177
registered_num != level_num,
173178
'Level {!r} already registered in logging module'.format(level_name),
@@ -229,4 +234,5 @@ def label_func(func):
229234
setattr(logger_class, method_name, for_logger_class)
230235
setattr(logger_adapter, method_name, for_logger_adapter)
231236
finally:
232-
logging._releaseLock()
237+
if '_releaseLock' in dir(logging):
238+
logging._releaseLock()

0 commit comments

Comments
 (0)