SaliencyMapDemo / src /reporter.py
umyuu
flake8
8ccf878
raw
history blame
1.32 kB
# -*- coding: utf-8 -*-
"""
Reporter
ใƒญใ‚ฐใƒใƒณใƒ‰ใƒฉใƒผใŒ้‡่ค‡็™ป้Œฒใ•ใ‚Œใ‚‹ใฎใ‚’้˜ฒใใŸใ‚ใซ1็ฎ‡ๆ‰€ใง็”Ÿๆˆใ—ใฆใƒญใ‚ฐใƒใƒณใƒ‰ใƒฉใƒผใ‚’่ฟ”ใ—ใพใ™ใ€‚
Example:
from reporter import get_current_reporter
logger = get_current_reporter()
logger.info("message");
"""
from logging import Logger, getLogger, Formatter, StreamHandler
from logging import DEBUG
_reporters = []
def get_current_reporter() -> Logger:
"""
ใ‚ทใƒณใ‚ฐใƒซใƒˆใƒณ
"""
return _reporters[-1]
def __make_reporter(name: str = 'SaliencyMapDemo') -> None:
"""
ใƒญใ‚ฐใƒใƒณใƒ‰ใƒฉใƒผใ‚’็”Ÿๆˆใ—ใพใ™ใ€‚
@see https://docs.python.jp/3/howto/logging-cookbook.html
Parameters:
name: ใ‚ขใƒ—ใƒชๅ
"""
handler = StreamHandler() # ใ‚ณใƒณใ‚ฝใƒผใƒซใซๅ‡บๅŠ›ใ—ใพใ™ใ€‚
formatter = Formatter('%(asctime)s%(message)s')
handler.setFormatter(formatter)
handler.setLevel(DEBUG)
logger = getLogger(name)
logger.setLevel(DEBUG)
logger.addHandler(handler)
_reporters.append(logger)
__make_reporter()
def main():
"""
Entry Point
"""
assert len(_reporters) == 1
logger = get_current_reporter()
logger.debug("main")
if __name__ == "__main__":
main()