<commit_before>import logging

from eventlet import greenthread


class gThread(object):
    name = None

    def __init__(self):
        if self.name is None:
            self.name = self.__class__.__name__
        self.logger = logging.getLogger(self.name)

    def start(self):
        return greenthread.spawn(self.run)

    def run(self):
        raise NotImplementedError("gThreads must implement 'run'")

    def debug(self, t):
        return self._log(logging.DEBUG, t)

    def info(self, t):
        return self._log(logging.INFO, t)

    def warn(self, t):
        return self._log(logging.WARN, t)

    def error(self, t):
        return self._log(logging.ERROR, t)

    def _log(self, severity, t):
        return self.logger.log(severity, "%s: %s" % (self.name, t, ))<commit_msg>Adds gThread.before + .after and logging convenience methods now supports kwargs, and multiple *args that is automatically sent through safe_str<commit_after>import logging

from celery.utils.encoding import safe_str
from eventlet import greenthread


class gThread(object):
    name = None

    def __init__(self):
        if self.name is None:
            self.name = self.__class__.__name__
        self.logger = logging.getLogger(self.name)

    def before(self):
        pass

    def after(self):
        pass

    def start(self):
        self.before()
        try:
            return greenthread.spawn(self.run)
        finally:
            self.after()

    def run(self):
        raise NotImplementedError("gThreads must implement 'run'")

    def debug(self, *args, **kwargs):
        return self._log(logging.DEBUG, *args, **kwargs)

    def info(self, *args, **kwargs):
        return self._log(logging.INFO, *args, **kwargs)

    def warn(self, *args, **kwargs):
        return self._log(logging.WARN, *args, **kwargs)

    def error(self, *args, **kwargs):
        return self._log(logging.ERROR, *args, **kwargs)

    def _log(self, severity, *args, **kwargs):
        body = "{%s} %s" % (self.name, " ".join(map(safe_str, args)))
        return self.logger.log(severity, body, **kwargs)
{'fraction_non_alphanumeric': 0.1235097758702909, 'fraction_numerical': 0.0, 'mean_word_length': 2.6871704745166958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '451735', 'n_tokens_mistral': 658, 'n_tokens_neox': 634, 'n_words': 175}