def testRedir(self): """ Test redirection to stream. """ with TestRedir.StdoutCapture(self.outputFilename): log.configure() dest = io.StringIO() log_utils.enable_notebook_logging(dest) log.log(log.getDefaultLogger().getName(), log.INFO, "This is INFO") log.info(u"This is unicode INFO") log.trace("This is TRACE") log.debug("This is DEBUG") log.warn("This is WARN") log.error("This is ERROR") log.fatal("This is FATAL") log_utils.disable_notebook_logging() log.warn("Format %d %g %s", 3, 2.71828, "foo") self.assertEqual( dest.getvalue(), """root INFO: This is INFO root INFO: This is unicode INFO root WARN: This is WARN root ERROR: This is ERROR root FATAL: This is FATAL """, ) self.check( """ root WARN: Format 3 2.71828 foo """ )
def testBasic(self): """ Test basic log output with default configuration. Since the default threshold is INFO, the DEBUG or TRACE message is not emitted. """ with TestLog.StdoutCapture(self.outputFilename): log.configure() log.log(log.getDefaultLogger(), log.INFO, "This is INFO") log.info(u"This is unicode INFO") log.trace("This is TRACE") log.debug("This is DEBUG") log.warn("This is WARN") log.error("This is ERROR") log.fatal("This is FATAL") log.critical("This is CRITICAL") log.warning("Format %d %g %s", 3, 2.71828, "foo") self.check(""" root INFO: This is INFO root INFO: This is unicode INFO root WARN: This is WARN root ERROR: This is ERROR root FATAL: This is FATAL root FATAL: This is CRITICAL root WARN: Format 3 2.71828 foo """)
def testBasicFormat(self): """ Test basic log output with default configuration but using the f variants. Since the default threshold is INFO, the DEBUG or TRACE message is not emitted. """ with TestLog.StdoutCapture(self.outputFilename): log.configure() log.logf(log.getDefaultLogger(), log.INFO, "This is {{INFO}} Item 1: {item[1]}", item=["a", "b", "c"]) log.infof(u"This is {unicode} INFO") log.tracef("This is TRACE") log.debugf("This is DEBUG") log.warnf("This is WARN {city}", city="Tucson") log.errorf("This is ERROR {1}->{0}", 2, 1) log.fatalf("This is FATAL {1} out of {0} times for {place}", 4, 3, place="LSST") log.warnf("Format {} {} {}", 3, 2.71828, "foo") self.check(""" root INFO: This is {INFO} Item 1: b root INFO: This is {unicode} INFO root WARN: This is WARN Tucson root ERROR: This is ERROR 1->2 root FATAL: This is FATAL 3 out of 4 times for LSST root WARN: Format 3 2.71828 foo """)
def testBasicFormat(self): """ Test basic log output with default configuration but using the f variants. Since the default threshold is INFO, the DEBUG or TRACE message is not emitted. """ with TestLog.StdoutCapture(self.outputFilename): log.configure() log.logf(log.getDefaultLogger(), log.INFO, "This is {{INFO}} Item 1: {item[1]}", item=["a", "b", "c"]) log.infof(u"This is {unicode} INFO") log.tracef("This is TRACE") log.debugf("This is DEBUG") log.warnf("This is WARN {city}", city="Tucson") log.errorf("This is ERROR {1}->{0}", 2, 1) log.fatalf("This is FATAL {1} out of {0} times for {place}", 4, 3, place="LSST") log.warnf("Format {} {} {}", 3, 2.71828, "foo") self.check(""" root INFO: This is {INFO} Item 1: b root INFO: This is {unicode} INFO root WARN: This is WARN Tucson root ERROR: This is ERROR 1->2 root FATAL: This is FATAL 3 out of 4 times for LSST root WARN: Format 3 2.71828 foo """)
def testChildLogger(self): """Check the getChild logger method.""" logger = log.getDefaultLogger() self.assertEqual(logger.getName(), "") logger1 = logger.getChild("child1") self.assertEqual(logger1.getName(), "child1") logger2 = logger1.getChild("child2") self.assertEqual(logger2.getName(), "child1.child2") logger2a = logger1.getChild(".child2") self.assertEqual(logger2a.getName(), "child1.child2") logger3 = logger2.getChild(" .. child3") self.assertEqual(logger3.getName(), "child1.child2.child3") logger3a = logger1.getChild("child2.child3") self.assertEqual(logger3a.getName(), "child1.child2.child3")
def testChildLogger(self): """Check the getChild logger method.""" logger = log.getDefaultLogger() self.assertEqual(logger.getName(), "") logger1 = logger.getChild("child1") self.assertEqual(logger1.getName(), "child1") logger2 = logger1.getChild("child2") self.assertEqual(logger2.getName(), "child1.child2") logger2a = logger1.getChild(".child2") self.assertEqual(logger2a.getName(), "child1.child2") logger3 = logger2.getChild(" .. child3") self.assertEqual(logger3.getName(), "child1.child2.child3") logger3a = logger1.getChild("child2.child3") self.assertEqual(logger3a.getName(), "child1.child2.child3")
def testBasic(self): """ Test basic log output with default configuration. Since the default threshold is INFO, the DEBUG or TRACE message is not emitted. """ with TestLog.StdoutCapture(self.outputFilename): log.configure() log.log(log.getDefaultLogger(), log.INFO, "This is INFO") log.info(u"This is unicode INFO") log.trace("This is TRACE") log.debug("This is DEBUG") log.warn("This is WARN") log.error("This is ERROR") log.fatal("This is FATAL") log.warning("Format %d %g %s", 3, 2.71828, "foo") self.check(""" root INFO: This is INFO root INFO: This is unicode INFO root WARN: This is WARN root ERROR: This is ERROR root FATAL: This is FATAL root WARN: Format 3 2.71828 foo """)
def testDefaultLogger(self): """Check the default root logger name.""" self.assertEqual(log.getDefaultLogger().getName(), "")
def testDefaultLogger(self): """Check the default root logger name.""" self.assertEqual(log.getDefaultLogger().getName(), "")