Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions logzero/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
# Formatter defaults
DEFAULT_FORMAT = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s'
DEFAULT_DATE_FORMAT = '%y%m%d %H:%M:%S'
DEFAULT_FILE_ENCODING = "utf-8"
DEFAULT_COLORS = {
DEBUG: ForegroundColors.CYAN,
INFO: ForegroundColors.GREEN,
Expand Down Expand Up @@ -98,7 +99,7 @@
colorama_init()


def setup_logger(name=__name__, logfile=None, level=DEBUG, formatter=None, maxBytes=0, backupCount=0, fileLoglevel=None, disableStderrLogger=False, isRootLogger=False, json=False, json_ensure_ascii=False):
def setup_logger(name=__name__, logfile=None, level=DEBUG, formatter=None, maxBytes=0, backupCount=0, fileLoglevel=None, disableStderrLogger=False, isRootLogger=False, json=False, json_ensure_ascii=False, encoding=DEFAULT_FILE_ENCODING):
"""
Configures and returns a fully configured logger instance, no hassles.
If a logger with the specified name already exists, it returns the existing instance,
Expand Down Expand Up @@ -166,7 +167,7 @@ def setup_logger(name=__name__, logfile=None, level=DEBUG, formatter=None, maxBy
_logger.addHandler(stderr_stream_handler)

if logfile:
rotating_filehandler = RotatingFileHandler(filename=logfile, maxBytes=maxBytes, backupCount=backupCount)
rotating_filehandler = RotatingFileHandler(filename=logfile, maxBytes=maxBytes, backupCount=backupCount, encoding=encoding)
setattr(rotating_filehandler, LOGZERO_INTERNAL_LOGGER_ATTR, True)
rotating_filehandler.setLevel(fileLoglevel or level)
rotating_filehandler.setFormatter(_formatter)
Expand Down