MCPcopy
hub / github.com/PaddlePaddle/PaddleOCR / get_logger

Function get_logger

ppocr/utils/logging.py:29–78  ·  view source on GitHub ↗

Initialize and get a logger by name. If the logger has not been initialized, this method will initialize the logger by adding one or two handlers, otherwise the initialized logger will be directly returned. During initialization, a StreamHandler will always be added. If `log_file` is

(name="ppocr", log_file=None, log_level=logging.DEBUG, log_ranks="0")

Source from the content-addressed store, hash-verified

27
28@functools.lru_cache()
29def get_logger(name="ppocr", log_file=None, log_level=logging.DEBUG, log_ranks="0"):
30 """Initialize and get a logger by name.
31 If the logger has not been initialized, this method will initialize the
32 logger by adding one or two handlers, otherwise the initialized logger will
33 be directly returned. During initialization, a StreamHandler will always be
34 added. If `log_file` is specified a FileHandler will also be added.
35 Args:
36 name (str): Logger name.
37 log_file (str | None): The log filename. If specified, a FileHandler
38 will be added to the logger.
39 log_level (int): The logger level. Note that only the process of
40 rank 0 is affected, and other processes will set the level to
41 "Error" thus be silent most of the time.
42 log_ranks (str): The ids of gpu to log which are separated by "," when more than 1, "0" by default.
43 Returns:
44 logging.Logger: The expected logger.
45 """
46 logger = logging.getLogger(name)
47 if name in logger_initialized:
48 return logger
49 for logger_name in logger_initialized:
50 if name.startswith(logger_name):
51 return logger
52
53 formatter = logging.Formatter(
54 "[%(asctime)s] %(name)s %(levelname)s: %(message)s", datefmt="%Y/%m/%d %H:%M:%S"
55 )
56
57 stream_handler = logging.StreamHandler(stream=sys.stdout)
58 stream_handler.setFormatter(formatter)
59 logger.addHandler(stream_handler)
60 if log_file is not None and dist.get_rank() == 0:
61 log_file_folder = os.path.split(log_file)[0]
62 os.makedirs(log_file_folder, exist_ok=True)
63 file_handler = logging.FileHandler(log_file, "a")
64 file_handler.setFormatter(formatter)
65 logger.addHandler(file_handler)
66
67 if isinstance(log_ranks, str):
68 log_ranks = [int(i) for i in log_ranks.split(",")]
69 elif isinstance(log_ranks, int):
70 log_ranks = [log_ranks]
71
72 if dist.get_rank() in log_ranks:
73 logger.setLevel(log_level)
74 else:
75 logger.setLevel(logging.ERROR)
76 logger_initialized[name] = True
77 logger.propagate = False
78 return logger

Callers 15

_downloadFunction · 0.90
load_modelFunction · 0.90
load_pretrained_paramsFunction · 0.90
exportFunction · 0.90
__init__Method · 0.90
__init__Method · 0.90
preprocessFunction · 0.90
preprocessFunction · 0.90
test_hubserving.pyFile · 0.90
get_infer_gpuidFunction · 0.90
predict_rec.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…