mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
refactoring modules structure | improving README and CHANGELOG
This commit is contained in:
22
bauh/view/util/logs.py
Normal file
22
bauh/view/util/logs.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import logging
|
||||
from logging import INFO
|
||||
|
||||
FORMAT = '%(asctime)s %(levelname)s [%(module_path)s:%(lineno)s - %(funcName)s()] - %(message)s'
|
||||
|
||||
|
||||
class FilePathFilter(logging.Filter):
|
||||
|
||||
def filter(self, record):
|
||||
record.module_path = record.pathname.split('site-packages/')[1] if 'site-packages' in record.pathname else str(record.pathname)
|
||||
return True
|
||||
|
||||
|
||||
def new_logger(name: str, enabled: bool) -> logging.Logger:
|
||||
instance = logging.Logger(name, level=INFO)
|
||||
instance.addFilter(FilePathFilter())
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(logging.Formatter(FORMAT))
|
||||
instance.addHandler(stream_handler)
|
||||
instance.disabled = not enabled
|
||||
|
||||
return instance
|
||||
Reference in New Issue
Block a user