コード例 #1
0
ファイル: tests.py プロジェクト: xolox/python-coloredlogs
 def test_plain_text_output_format(self):
     """Inspect the plain text output of coloredlogs."""
     logger = VerboseLogger(random_string(25))
     stream = StringIO()
     install(level=logging.NOTSET, logger=logger, stream=stream)
     # Test that filtering on severity works.
     logger.setLevel(logging.INFO)
     logger.debug("No one should see this message.")
     assert len(stream.getvalue().strip()) == 0
     # Test that the default output format looks okay in plain text.
     logger.setLevel(logging.NOTSET)
     for method, severity in ((logger.debug, 'DEBUG'),
                              (logger.info, 'INFO'),
                              (logger.verbose, 'VERBOSE'),
                              (logger.warning, 'WARNING'),
                              (logger.error, 'ERROR'),
                              (logger.critical, 'CRITICAL')):
         # Prepare the text.
         text = "This is a message with severity %r." % severity.lower()
         # Log the message with the given severity.
         method(text)
         # Get the line of output generated by the handler.
         output = stream.getvalue()
         lines = output.splitlines()
         last_line = lines[-1]
         assert text in last_line
         assert severity in last_line
         assert PLAIN_TEXT_PATTERN.match(last_line)
コード例 #2
0
ファイル: tests.py プロジェクト: ddboline/python-coloredlogs
 def test_plain_text_output_format(self):
     """Inspect the plain text output of coloredlogs."""
     logger = VerboseLogger(random_string(25))
     stream = StringIO()
     install(level=logging.NOTSET, logger=logger, stream=stream)
     # Test that filtering on severity works.
     logger.setLevel(logging.INFO)
     logger.debug("No one should see this message.")
     assert len(stream.getvalue().strip()) == 0
     # Test that the default output format looks okay in plain text.
     logger.setLevel(logging.NOTSET)
     for method, severity in ((logger.debug, 'DEBUG'), (logger.info,
                                                        'INFO'),
                              (logger.verbose, 'VERBOSE'), (logger.warning,
                                                            'WARN'),
                              (logger.error, 'ERROR'), (logger.critical,
                                                        'CRITICAL')):
         # Prepare the text.
         text = "This is a message with severity %r." % severity.lower()
         # Log the message with the given severity.
         method(text)
         # Get the line of output generated by the handler.
         output = stream.getvalue()
         lines = output.splitlines()
         last_line = lines[-1]
         assert text in last_line
         assert severity in last_line
         assert PLAIN_TEXT_PATTERN.match(last_line)
コード例 #3
0
 def test_plain_text_output_format(self):
     """Inspect the plain text output of coloredlogs."""
     logger = VerboseLogger(random_string(25))
     stream = StringIO()
     install(level=logging.NOTSET, logger=logger, stream=stream)
     # Test that filtering on severity works.
     logger.setLevel(logging.INFO)
     logger.debug("No one should see this message.")
     assert len(stream.getvalue().strip()) == 0
     # Test that the default output format looks okay in plain text.
     logger.setLevel(logging.NOTSET)
     for method, severity in ((logger.debug, 'DEBUG'),
                              (logger.info, 'INFO'),
                              (logger.verbose, 'VERBOSE'),
                              (logger.warning, 'WARNING'),
                              (logger.error, 'ERROR'),
                              (logger.critical, 'CRITICAL')):
         # XXX Workaround for a regression in Python 3.7 caused by the
         # Logger.isEnabledFor() method using stale cache entries. If we
         # don't clear the cache then logger.isEnabledFor(logging.DEBUG)
         # returns False and no DEBUG message is emitted.
         try:
             logger._cache.clear()
         except AttributeError:
             pass
         # Prepare the text.
         text = "This is a message with severity %r." % severity.lower()
         # Log the message with the given severity.
         method(text)
         # Get the line of output generated by the handler.
         output = stream.getvalue()
         lines = output.splitlines()
         last_line = lines[-1]
         assert text in last_line
         assert severity in last_line
         assert PLAIN_TEXT_PATTERN.match(last_line)