Remove timestamp from logs in notebooks

This commit is contained in:
Andras Schmelczer 2022-07-11 19:32:45 +02:00
parent 8d1ad9a242
commit 68c7da38b8
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E
2 changed files with 159 additions and 33 deletions

View file

@ -9,13 +9,22 @@ loggers: Dict[str, logging.Logger] = {}
def get_logger(
name: str, level: int = logging.INFO, disable_colors: bool = False
) -> logging.Logger:
"""Return a customised logger used throughout the GreatAI codebase."""
"""Return a customised logger used throughout the GreatAI codebase.
Uses colors, and only prints timestamps when not running inside notebook.
"""
if name not in loggers:
logger = logging.getLogger(name)
logger.setLevel(level)
log_format = "%(asctime)s | %(levelname)8s | %(message)s"
try:
get_ipython() # type: ignore
log_format = "%(message)s"
except NameError:
# will fail outside of a notebook https://ipython.org/
log_format = "%(asctime)s | %(levelname)8s | %(message)s"
stdout_handler = logging.StreamHandler()
stdout_handler.setLevel(level)
if not disable_colors: