Skip to content

Commit

Permalink
Try to fix logger issues in Python 3.5 ad 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
17451k committed Dec 31, 2020
1 parent 092cb87 commit 1011564
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 15 additions & 1 deletion clade/extensions/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def __init__(self, work_dir, conf=None):
self.temp_dir = ""

self.conf = conf if conf else dict()
self.logger = get_logger("clade", with_name=False, conf=self.conf)

self.logger = None

if not hasattr(self, "requires"):
self.requires = []
Expand Down Expand Up @@ -563,6 +564,7 @@ def log(self, message):
self.conf["log_level"] must be set to INFO or DEBUG in order to see the message.
"""
self.__get_logger()
self.logger.info("{}: {}".format(self.name, message))

def debug(self, message):
Expand All @@ -572,18 +574,30 @@ def debug(self, message):
WARNING: debug messages can have a great impact on the performance.
"""
self.__get_logger()
self.logger.debug("{}: [DEBUG] {}".format(self.name, message))

def warning(self, message):
"""Print warning message.
self.conf["log_level"] must be set to WARNING, INFO or DEBUG in order to see the message.
"""
self.__get_logger()
self.logger.warning("{}: [WARNING] {}".format(self.name, message))

def error(self, message):
"""Print error message.
self.conf["log_level"] must be set to ERROR, WARNING, INFO or DEBUG in order to see the message.
"""
self.__get_logger()
self.logger.error("{}: [ERROR] {}".format(self.name, message))

def __get_logger(self):
# Initializing logger this way serves two purposes:
# - as a workaround for multiprocessing not supporting passing logger
# objects in Python 3.5 and 3.6
# - and to setup logger in subprocesses

if not self.logger:
self.logger = get_logger("clade", with_name=False, conf=self.conf)
3 changes: 0 additions & 3 deletions clade/extensions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
from clade.extensions.abstract import Extension
from clade.extensions.opts import requires_value
from clade.cmds import iter_cmds_by_which, number_of_cmds_by_which
from clade.utils import get_logger


def unwrap(self, cmd):
# Subprocesses need to setup logger again
self.logger = get_logger("clade", with_name=False, conf=self.conf)
return self.parse_cmd(cmd)


Expand Down

0 comments on commit 1011564

Please sign in to comment.