Ejemplo n.º 1
0
 def test_scribify(self):
     # The rhs is intentionally native strings
     assert scribify(b'stream_service_errors') == str(
         'stream_service_errors')
     assert scribify("this is a test") == str('this_is_a_test')
     assert scribify("this\0is a-test\n\n") == str('this_is_a-test__')
     assert scribify(u'int\xe9rna\xe7ionalization') == str(
         'int_rna_ionalization')
Ejemplo n.º 2
0
    def _log_line_no_size_limit(self, stream, line):
        """Log a single line without size limit. It should not include any newline characters.
           Since this method is called in log_line, the line should be in utf-8 format and
           less than MAX_LINE_SIZE_IN_BYTES already. We don't limit traceback size.
        """
        with self.__lock:
            if os.getpid() != self._birth_pid:
                raise ScribeIsNotForkSafeError
            if not self.connected:
                self._maybe_reconnect()

            if self.connected:
                log_entry = scribe_thrift.LogEntry(category=scribify(stream), message=line + b'\n')
                try:
                    return self.client.Log(messages=[log_entry])
                except Exception as e:
                    try:
                        self.report_status(
                            True,
                            'yelp_clog failed to log to scribe server with '
                            ' exception: %s(%s)' % (type(e), six.text_type(e))
                        )
                    finally:
                        self.close()
                        self.last_connect_time = time.time()

                    # Don't reconnect if report_status raises an exception
                    self._maybe_reconnect()
Ejemplo n.º 3
0
def add_logger_to_scribe(logger,
                         log_level=logging.INFO,
                         fmt=DEFAULT_FORMAT,
                         clogger_object=None):
    """Sets up a logger to log to scribe.

    By default, messages at the INFO level and higher will go to scribe.

    .. deprecated:: 0.1.6

    .. warning::

        This function is deprecated in favor of using :func:`clog.log_line` or
        :class:`ScribeHandler` directly.

    :param logger: A logging.Logger instance
    :param log_level: The level to log at
    :param clogger_object: for use in testing
    """
    scribified_name = scribify(logger.name)
    if any(h.stream == scribified_name for h in logger.handlers
           if isinstance(h, CLogHandler)):
        return
    clog_handler = CLogHandler(scribified_name, logger=clogger_object)
    clog_handler.setLevel(log_level)
    clog_handler.setFormatter(logging.Formatter(fmt))
    logger.setLevel(log_level)
    logger.addHandler(clog_handler)
Ejemplo n.º 4
0
    def _log_line_no_size_limit(self, stream, line):
        """Log a single line without size limit. It should not include any newline characters.
           Since this method is called in log_line, the line should be in utf-8 format and
           less than MAX_LINE_SIZE_IN_BYTES already. We don't limit traceback size.
        """
        with self.__lock:
            if os.getpid() != self._birth_pid:
                raise ScribeIsNotForkSafeError
            if not self.connected:
                self._maybe_reconnect()

            if self.connected:
                log_entry = scribe_thrift.LogEntry(category=scribify(stream),
                                                   message=line + b'\n')
                try:
                    return self.client.Log(messages=[log_entry])
                except Exception as e:
                    try:
                        self.report_status(
                            True,
                            'yelp_clog failed to log to scribe server with '
                            ' exception: %s(%s)' % (type(e), six.text_type(e)))
                    finally:
                        self.close()
                        self.last_connect_time = time.time()

                    # Don't reconnect if report_status raises an exception
                    self._maybe_reconnect()
Ejemplo n.º 5
0
def add_logger_to_scribe(logger, log_level=logging.INFO, fmt=DEFAULT_FORMAT, clogger_object=None):
    """Sets up a logger to log to scribe.

    By default, messages at the INFO level and higher will go to scribe.

    .. deprecated:: 0.1.6

    .. warning::

        This function is deprecated in favor of using :func:`clog.log_line` or
        :class:`ScribeHandler` directly.

    :param logger: A logging.Logger instance
    :param log_level: The level to log at
    :param clogger_object: for use in testing
    """
    scribified_name = scribify(logger.name)
    if any (h.stream == scribified_name for h in logger.handlers if isinstance(h, CLogHandler)):
        return
    clog_handler = CLogHandler(scribified_name, logger=clogger_object)
    clog_handler.setLevel(log_level)
    clog_handler.setFormatter(logging.Formatter(fmt))
    logger.setLevel(log_level)
    logger.addHandler(clog_handler)
Ejemplo n.º 6
0
 def test_scribify(self):
     # The rhs is intentionally native strings
     assert scribify(b'stream_service_errors') == str('stream_service_errors')
     assert scribify("this is a test") == str('this_is_a_test')
     assert scribify("this\0is a-test\n\n") == str('this_is_a-test__')
     assert scribify(u'int\xe9rna\xe7ionalization') == str('int_rna_ionalization')
Ejemplo n.º 7
0
 def test_scribify(self):
     T.assert_equal(scribify("this is a test"), "this_is_a_test")
     T.assert_equal(scribify("this\0is a-test\n\n"), "this_is_a-test__")
     T.assert_equal(scribify(u'int\xe9rna\xe7ionalization'), 'int_rna_ionalization')