Skip to content

Commit 5eb4088

Browse files
committed
ADD: Function to setup logging for databento
1 parent df32618 commit 5eb4088

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

databento/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from databento.common import utility
34
from databento.common.bento import Bento
45
from databento.common.enums import (
56
Compression,
@@ -56,4 +57,5 @@
5657
logging.getLogger(__name__).addHandler(logging.NullHandler())
5758

5859
# Convenience imports
60+
enable_logging = utility.enable_logging
5961
from_dbn = Bento.from_file

databento/common/utility.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import logging
2+
from typing import Union
3+
4+
5+
def enable_logging(level: Union[int, str] = logging.INFO) -> None:
6+
"""
7+
Enable logging for the Databento module.
8+
This function should be used for simple applications and examples.
9+
It is advisible to configure your own logging for serious applications.
10+
11+
Parameters
12+
----------
13+
level : str or int, default 'INFO'
14+
The log level to configure.
15+
16+
See Also
17+
--------
18+
logging
19+
20+
"""
21+
# Create a basic formatter
22+
formatter = logging.Formatter(
23+
fmt=logging.BASIC_FORMAT,
24+
)
25+
26+
# Construct a stream handler for stderr
27+
handler = logging.StreamHandler()
28+
handler.setFormatter(formatter)
29+
handler.setLevel(level=level)
30+
31+
# Add the handler to the databento logger
32+
databento_logger = logging.getLogger("databento")
33+
databento_logger.setLevel(level=level)
34+
databento_logger.addHandler(handler)

0 commit comments

Comments
 (0)