def emit(self, record: logging.LogRecord):
if record.levelno != self.level:
return # only log the handlers level to the handlers channel, not above
msg = self.format(record)
start = msg.find('```py\n')
if start != -1:
msg, trace = msg[:start], msg[start:]
else:
trace = None
# the actual log message
for line in msg.split('\n'):
# if this is a small codeblock and goes over multiple messages it will break out
# so we check that each chunk (besides the first) starts and stops with a backtick
for idx, chunk in enumerate(line[x:x + 1994] for x in range(0, len(line), 1994)):
# ugh
if not chunk.endswith('`'):
chunk = f'{chunk}`'
if not chunk.startswith('`'):
chunk = f'`{chunk}'
self._buffer.append(chunk)
# the traceback, sent separately to be in a big codeblock for syntax highlighting
if trace is not None:
# cut off the original codeblock
trace = trace[6:-3]
paginator = commands.Paginator(prefix='```py\n', suffix='```')
for line in trace.split('\n'):
for chunk in (line[x:x + 1987] for x in range(0, len(line), 1987)):
paginator.add_line(chunk)
for page in paginator.pages:
self._buffer.append(page)
self._can_emit.set()
评论列表
文章目录