<commit_before>import logging
import sys
import traceback

from polyaxon_client import settings
from polyaxon_schemas.utils import local_now


class PolyaxonHandler(logging.Handler):
    DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z"

    def __init__(self, send_logs, **kwargs):
        self._send_logs = send_logs
        logging.Handler.__init__(self, level=kwargs.get('level', logging.NOTSET))

    def can_record(self, record):
        return not (
            record.name == 'polyaxon.client' or
            record.name == 'polyaxon.cli' or
            record.name.startswith('polyaxon')
        )

    def format_record(self, record):
        return '{} -- {} {}'.format(local_now().strftime(self.DATETIME_FORMAT),
                                    record.levelname,
                                    record.msg)

    def emit(self, record):  # pylint:disable=inconsistent-return-statements
        if settings.IN_CLUSTER or not self.can_record(record):
            return
        try:
            return self._send_logs(self.format_record(record))
        except Exception:
            print("Polyaxon failed creating log record", file=sys.stderr)
            print('{}'.format(record.msg), file=sys.stderr)
            print('{}'.format(traceback.format_exc()), file=sys.stderr)
<commit_msg>Update handler<commit_after>import logging

from polyaxon_client import settings
from polyaxon_schemas.utils import local_now

from polyaxon_client.logger import logger


class PolyaxonHandler(logging.Handler):
    DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z"

    def __init__(self, send_logs, **kwargs):
        self._send_logs = send_logs
        logging.Handler.__init__(self, level=kwargs.get('level', logging.NOTSET))

    def can_record(self, record):
        return not (
            record.name == 'polyaxon.client' or
            record.name == 'polyaxon.cli' or
            record.name.startswith('polyaxon')
        )

    def format_record(self, record):
        return '{} -- {} {}'.format(local_now().strftime(self.DATETIME_FORMAT),
                                    record.levelname,
                                    record.msg)

    def emit(self, record):  # pylint:disable=inconsistent-return-statements
        if settings.IN_CLUSTER or not self.can_record(record):
            return
        try:
            return self._send_logs(self.format_record(record))
        except Exception:
            logger.warning("Polyaxon failed creating log record")

{'fraction_non_alphanumeric': 0.11124595469255663, 'fraction_numerical': 0.0, 'mean_word_length': 2.4110344827586205, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5918847', 'n_tokens_mistral': 722, 'n_tokens_neox': 680, 'n_words': 142}