Last active
March 6, 2023 14:24
-
-
Save prrao87/8fe20449c8807028966a9ac5e626b40e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a logger with rotating file handler and formatting per loguru | |
def get_logger(filename: str): | |
import sys | |
from loguru import logger | |
from pathlib import Path | |
Path("logs").mkdir(parents=True, exist_ok=True) | |
logger.remove() # Remove base logger settings and overwrite with custom settings | |
fmt = "{time:HH:mm:ss:SSS} -- {level} -- {message}" | |
# Add rotating file handler with desired level of logging | |
filename = f"{filename}.log" if not filename.endswith(".log") else filename | |
logger.add(Path("logs") / filename, level="INFO", format=fmt, rotation="50 MB") | |
# Add console log with desired level of logging | |
logger.add(sys.stderr, level="DEBUG", format=fmt) | |
return logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment