0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Python] logger実装

Posted at

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)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?