MCPcopy Create free account
hub / github.com/FlyingFeather/DEA-SQL / setup_logger

Function setup_logger

logger.py:13–114  ·  view source on GitHub ↗

Initialize the GCL logger and set its verbosity level to "DEBUG". Args: output : Optional[str], optional a file name or a directory to save log. If None, will not save log file. If ends with ".txt" or ".log", assumed to be a file name. Otherwise, logs will be saved to

(
    output: Optional[str] = None, distributed_rank: int = 0, *, mode: str = 'w',
    color: bool = True, time: bool = True, name: str = "GCL", abbrev_name: Optional[str] = None
)

Source from the content-addressed store, hash-verified

11# with the same file name can safely write to the same file.
12@functools.lru_cache(maxsize=None)
13def setup_logger(
14 output: Optional[str] = None, distributed_rank: int = 0, *, mode: str = 'w',
15 color: bool = True, time: bool = True, name: str = "GCL", abbrev_name: Optional[str] = None
16):
17 """Initialize the GCL logger and set its verbosity level to "DEBUG".
18 Args:
19 output : Optional[str], optional
20 a file name or a directory to save log. If None, will not save log file.
21 If ends with ".txt" or ".log", assumed to be a file name.
22 Otherwise, logs will be saved to `output/log.txt`.
23 distributed_rank : int, optional
24 used for distributed training, by default 0
25 mode : str, optional
26 mode for the output file (if output is given), by default 'w'.
27 color : bool, optional
28 whether to use color when printing, by default True
29 name : str, optional
30 the root module name of this logger, by default "GCL"
31 abbrev_name : Optional[str], optional
32 an abbreviation of the module, to avoid long names in logs.
33 Set to "" to not log the root module in logs.
34 By default, None.
35 Returns
36 -------
37 logging.Logger
38 a logger
39 Example
40 -------
41 >>> logger = setup_logger(name='my exp')
42 >>> logger.info('message')
43 [12/19 17:01:43 my exp]: message
44 >>> logger.error('message')
45 ERROR [12/19 17:02:22 my exp]: message
46 >>> logger.warning('message')
47 WARNING [12/19 17:02:32 my exp]: message
48 >>> # specify output files
49 >>> logger = setup_logger(output='log.txt', name='my exp')
50 # additive, by default mode='w'
51 >>> logger = setup_logger(output='log.txt', name='my exp', mode='a')
52 # once you logger is set, you can call it by
53 >>> logger = get_logger(name='my exp')
54 """
55
56 logger = logging.getLogger(name)
57 logger.setLevel(logging.DEBUG)
58 logger.propagate = False
59
60 if abbrev_name is None:
61 abbrev_name = name
62
63 plain_formatter = logging.Formatter(
64 "[%(asctime)s] %(name)s %(levelname)s: %(message)s", datefmt="%Y/%m/%d %H:%M:%S"
65 )
66 plain_formatter_without_time = logging.Formatter()
67
68 # stdout logging: master only
69 if distributed_rank == 0:
70 ch = logging.StreamHandler(stream=sys.stdout)

Callers 1

main.pyFile · 0.90

Calls 1

_ColorfulFormatterClass · 0.85

Tested by

no test coverage detected