MCPcopy Create free account
hub / github.com/SooLab/CGFormer / StreamToLoguru

Class StreamToLoguru

utils/misc.py:228–254  ·  view source on GitHub ↗

stream object that redirects writes to a logger instance.

Source from the content-addressed store, hash-verified

226
227
228class StreamToLoguru:
229 """
230 stream object that redirects writes to a logger instance.
231 """
232 def __init__(self, level="INFO", caller_names=("apex", "pycocotools")):
233 """
234 Args:
235 level(str): log level string of loguru. Default value: "INFO".
236 caller_names(tuple): caller names of redirected module.
237 Default value: (apex, pycocotools).
238 """
239 self.level = level
240 self.linebuf = ""
241 self.caller_names = caller_names
242
243 def write(self, buf):
244 full_name = get_caller_name(depth=1)
245 module_name = full_name.rsplit(".", maxsplit=-1)[0]
246 if module_name in self.caller_names:
247 for line in buf.rstrip().splitlines():
248 # use caller level log
249 logger.opt(depth=2).log(self.level, line.rstrip())
250 else:
251 sys.__stdout__.write(buf)
252
253 def flush(self):
254 pass
255
256
257def redirect_sys_output(log_level="INFO"):

Callers 1

redirect_sys_outputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected