Beispiel #1
0
    def test_logging_proxy(self):
        with restore_logging():
            logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                       root=False)

            with wrap_logger(logger) as sio:
                p = LoggingProxy(logger, loglevel=logging.ERROR)
                p.close()
                p.write('foo')
                self.assertNotIn('foo', sio.getvalue())
                p.closed = False
                p.write('foo')
                self.assertIn('foo', sio.getvalue())
                lines = ['baz', 'xuzzy']
                p.writelines(lines)
                for line in lines:
                    self.assertIn(line, sio.getvalue())
                p.flush()
                p.close()
                self.assertFalse(p.isatty())

                with override_stdouts() as (stdout, stderr):
                    with in_sighandler():
                        p.write('foo')
                        self.assertTrue(stderr.getvalue())
Beispiel #2
0
 def test_redirect_stdouts(self):
     logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                root=False)
     try:
         with wrap_logger(logger) as sio:
             self.app.log.redirect_stdouts_to_logger(
                 logger, loglevel=logging.ERROR,
             )
             logger.error('foo')
             self.assertIn('foo', sio.getvalue())
             self.app.log.redirect_stdouts_to_logger(
                 logger, stdout=False, stderr=False,
             )
     finally:
         sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__
Beispiel #3
0
 def test_redirect_stdouts(self):
     with restore_logging():
         logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                    root=False)
         try:
             with wrap_logger(logger) as sio:
                 self.app.log.redirect_stdouts_to_logger(
                     logger, loglevel=logging.ERROR,
                 )
                 logger.error('foo')
                 self.assertIn('foo', sio.getvalue())
                 self.app.log.redirect_stdouts_to_logger(
                     logger, stdout=False, stderr=False,
                 )
         finally:
             sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__
Beispiel #4
0
    def test_logging_proxy(self):
        logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                   root=False)

        with wrap_logger(logger) as sio:
            p = LoggingProxy(logger, loglevel=logging.ERROR)
            p.close()
            p.write('foo')
            self.assertNotIn('foo', sio.getvalue())
            p.closed = False
            p.write('foo')
            self.assertIn('foo', sio.getvalue())
            lines = ['baz', 'xuzzy']
            p.writelines(lines)
            for line in lines:
                self.assertIn(line, sio.getvalue())
            p.flush()
            p.close()
            self.assertFalse(p.isatty())
Beispiel #5
0
    def _assertLog(self, logger, logmsg, loglevel=logging.ERROR):

        with wrap_logger(logger, loglevel=loglevel) as sio:
            logger.log(loglevel, logmsg)
            return sio.getvalue().strip()