Spaces:
Running
Running
File size: 1,335 Bytes
da8bdb9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# -*- 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#logging-to-a-single-file-from-multiple-processes
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()
|