Skip to content

Commit bd00058

Browse files
committed
util.logging.configure: Allow the stream to be configured
1 parent d70c57a commit bd00058

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* Use autocommit and remove option of using deferred commits as it's the only way to guarantee
1818
that no stale data is read due to transactions going on too long
1919
* Handle duplicate key upon insertion due to race condition by providing a more informative Exception
20+
* `util.logging`:
21+
* `configure`: Allow the output stream to be configured
2022

2123

2224
## 1.4.0 (2025-01-21)

src/sensai/util/logging.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,21 @@ def set_configure_callback(callback: Callable[[], None], append: bool = True) ->
6868

6969

7070
# noinspection PyShadowingBuiltins
71-
def configure(format=LOG_DEFAULT_FORMAT, level=lg.DEBUG):
71+
def configure(format=LOG_DEFAULT_FORMAT, level=lg.DEBUG, stream=sys.stdout):
7272
"""
73-
Configures logging to stdout with the given format and log level,
73+
Configures logging to the given stream with the given format and log level,
7474
also configuring the default log levels of some overly verbose libraries as well as some pandas output options.
7575
76+
Note: the configuration can be extended by registering a callback via :func:`set_configure_callback`.
77+
7678
:param format: the log format
7779
:param level: the minimum log level
80+
:param stram: the output stream for whcih to configure a log handler
7881
"""
7982
global _logFormat
8083
_logFormat = format
8184
remove_log_handlers()
82-
basicConfig(level=level, format=format, stream=sys.stdout)
85+
basicConfig(level=level, format=format, stream=stream)
8386
getLogger("matplotlib").setLevel(lg.INFO)
8487
getLogger("urllib3").setLevel(lg.INFO)
8588
getLogger("msal").setLevel(lg.INFO)

0 commit comments

Comments
 (0)