loggerの実装
logger.py
from logging import getLogger, StreamHandler, INFO, Formatter
def main():
logger = get_logger()
logger.info("logger実装")
// [INFO]2023-06-08 22:35:49,969-logger実装(logger.py)
def get_logger():
logger = getLogger("log")
handler = StreamHandler()
handler.setLevel(INFO)
logger.setLevel(INFO)
logger.addHandler(handler)
formatter = Formatter('[%(levelname)s]%(asctime)s-%(message)s(%(filename)s)')
handler.setFormatter(formatter)
return logger
if __name__ == "__main__":
main()
他のclassでも使用する場合
test.py
logger = getLogger("log")
logger.info("logger test")
// [INFO]2023-06-08 22:35:49,969-read args(test.py)