Spaces:
Sleeping
Sleeping
# -*- 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() | |