【发布时间】:2014-10-09 12:59:03
【问题描述】:
我找不到压缩使用logger 模块编写的日志的方法。
例如:
import logging
import gzip
logger = logging.getLogger('')
z_file = gzip.open('out.log.gz', mode='wb')
logger.addHandler(logging.StreamHandler(z_file))
logger.warning("test".encode("UTF-8"))
codecs.open和gzip.open都给我
--- Logging error ---
Traceback (most recent call last):
File "/usr/lib/python3.4/logging/__init__.py", line 966, in emit
stream.write(msg)
File "/usr/lib/python3.4/gzip.py", line 343, in write
self.crc = zlib.crc32(data, self.crc) & 0xffffffff
TypeError: 'str' does not support the buffer interface
当我尝试使用他们的处理程序时。我做错了什么?
不包含logger模块的相关问题:Writing append only gzipped log files in Python
【问题讨论】:
-
请创建最短的完整程序来演示您看到的错误。将该简短而完整的程序复制粘贴到您的问题中。
-
@Robᵩ,完成。更新了问题。
标签: python logging python-3.x compression