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