blockutils.logging
¶
Utility to create logger instances.
get_logger(name, level=10)
¶
Instantiate a logger with a given level and name.
Examples:
logger = blockutils.logging.get_logger(__name__)
# __name__ is the name of the file where the logger is instantiated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str |
A name for the logger - is included in all the logging messages. |
required |
level |
A logging level (i.e. logging.DEBUG). |
10 |
Returns:
Type | Description |
---|---|
Logger |
A logger instance. |
Source code in blockutils/logging.py
def get_logger(name: str, level=logging.DEBUG) -> logging.Logger:
"""
Instantiate a logger with a given level and name.
Example:
```python
logger = blockutils.logging.get_logger(__name__)
# __name__ is the name of the file where the logger is instantiated.
```
Arguments:
name: A name for the logger - is included in all the logging messages.
level: A logging level (i.e. logging.DEBUG).
Returns:
A logger instance.
"""
logger = logging.getLogger(name)
logger.setLevel(level)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(level)
formatter = logging.Formatter(LOG_FORMAT)
ch.setFormatter(formatter)
logger.addHandler(ch)
return logger