def emit(self, record):
"""
Emit a record.
If a formatter is specified, it is used to format the record.
The record is then written to the stream with a trailing newline. If
exception information is present, it is formatted using
traceback.print_exception and appended to the stream. If the stream
has an 'encoding' attribute, it is used to determine how to do the
output to the stream.
"""
try:
msg = self.format(record)
stream = self.stream
fs = "%s\n"
if not _unicode: #if no unicode support...
stream.write(fs % msg)
else:
try:
if (isinstance(msg, unicode) and
getattr(stream, 'encoding', None)):
ufs = fs.decode(stream.encoding)
python logging 模块,logger.debug(),logger.info()等写入文件时的核心源码
最新推荐文章于 2023-10-16 20:37:07 发布
本文将详细剖析Python logging模块中,logger.debug()、logger.info()等方法将日志写入文件的核心源码。通过理解关键函数emit(),了解如何格式化日志记录,并确保在不同编码环境下正确输出到文件。
摘要由CSDN通过智能技术生成