uio.utility.logs.log
Logging customization.
1""" 2Logging customization. 3""" 4 5import sys 6import logging 7 8from . import debugMode 9 10_loggingLevel: int = logging.INFO 11_loggingFormat: str = "[%(levelname)s] %(message)s" 12if debugMode: 13 _loggingLevel = logging.DEBUG 14 # 8 is the length of "CRITICAL" - the longest log level name 15 _loggingFormat = "%(asctime)s | %(levelname)-8s | %(message)s" 16_formatter = logging.Formatter(_loggingFormat) 17 18# create a separate logger, so it doesn't override 19# logging settings in consuming projects 20logger = logging.getLogger("uio-exoplanet-group") 21""" 22Pre-made logger object with custom formatting, printing messages 23to standard output (stdout). 24 25Example: 26 27``` py 28from uio.utility.logs.log import logger 29 30logger.debug("Some debug message") 31logger.info("Some regular message") 32``` 33 34With `uio.utility.logs.debugMode` is set to `False` the output will be: 35 36``` 37[INFO] Some regular message 38``` 39 40otherwise: 41 42``` 432023-11-26 14:52:13,692 | DEBUG | Some debug message 442023-11-26 14:52:13,693 | INFO | Some regular message 45``` 46""" 47 48logger.setLevel(_loggingLevel) 49# # disable default handler, so it doesn't duplicate logging 50logger.propagate = False 51 52_streamHandler = logging.StreamHandler(sys.stdout) 53_streamHandler.setFormatter(_formatter) 54 55logger.addHandler(_streamHandler)
logger =
<Logger uio-exoplanet-group (INFO)>
Pre-made logger object with custom formatting, printing messages to standard output (stdout).
Example:
from uio.utility.logs.log import logger
logger.debug("Some debug message")
logger.info("Some regular message")
With uio.utility.logs.debugMode
is set to False
the output will be:
[INFO] Some regular message
otherwise:
2023-11-26 14:52:13,692 | DEBUG | Some debug message
2023-11-26 14:52:13,693 | INFO | Some regular message