palpen / DALLEePaperFrame

MIT License
1 stars 0 forks source link

Replace print statements with logging functions #8

Open palpen opened 2 years ago

palpen commented 2 years ago

Code for how to do this

import logging
from logging.handlers import RotatingFileHandler

LOG_LEVEL = logging.INFO

logging.basicConfig(
    handlers=[RotatingFileHandler('client.log', maxBytes=100000, backupCount=10)],
    level=LOG_LEVEL,
    format="[%(asctime)s] %(levelname)s [%(filename)s.%(module)s.%(funcName)s:%(lineno)d] %(message)s",
    datefmt='%Y-%m-%dT%H:%M:%S'
)
logger = logging.getLogger('client_logger')

# Testing
def foo():
    logger.info("Log in function")
    return None

for i in range(1000):
    foo()
    logger.info(f"This is an info {i}")
    logger.debug('Hello, world!')