concurrent-log-handler: py27 TypeError: write() argument 1 must be unicode, not str

Looks like the default terminator of ‘\n’ isn’t happy being written to an io stream due to the default encoding. A work around is to set terminator to u’\n’. Is there a better fix for this though?

__init__.py, line 337, in do_write
    stream.write(self.terminator)
TypeError: write() argument 1 must be unicode, not str

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Seems to be working fine here too! Thanks again!

Thank you Preston - Looks good!

Hi Preston,

Tested this morning with the following code, Windows 10, Python 2.7.13 and Python 3.7.2. Everything is working great. Thanks!

import os
import logging
from concurrent_log_handler import ConcurrentRotatingFileHandler


def test_unicode_logging():
    root_logger = logging.getLogger()
    root_logger.setLevel(logging.DEBUG)
    file_formatter = logging.Formatter(
        fmt="%(asctime)s [%(name)s] [%(levelname)s] %(message)s", datefmt='%Y-%m-%d %H:%M:%S')
    log_filename = r'test.txt'
    file_handler = ConcurrentRotatingFileHandler(
        log_filename,
        maxBytes= 10*1024,
        backupCount=30,
    )
    file_handler.setFormatter(file_formatter)
    file_handler.setLevel(logging.DEBUG)
    root_logger.addHandler(file_handler)
    root_logger.info('logging to rotating file: {}'.format(os.path.abspath(log_filename)))
    for _ in range(10000):
        logging.warning('this is a test string\n'*100)