def run(test): """ """ resetLogging() basehdlr = TestHandler(test, 5) fmt = logging.Formatter(style="{") basehdlr.setFormatter(fmt) logging.basicConfig(handlers=[basehdlr], level=logging.INFO) root = logging.getLogger() test.check(root.hasHandlers()) test.check(root.level) test.check(len(root.handlers)) hdlr = root.handlers[0] test.check(hdlr.level) logging.debug("Never gonna give you up") logging.info("Never gonna let you go") logging.warning("Never gonna run around and desert you") logging.error("Never gonna make you cry") root.setLevel(logging.DEBUG) logging.debug("Never gonna give you up") logging.info("Never gonna let you go") logging.warning("Never gonna run around and desert you") logging.error("Never gonna make you cry")
def run(test): """ """ resetLogging() basehdlr = TestHandler(test, 5) fmt = logging.Formatter(style="{") basehdlr.setFormatter(fmt) logging.basicConfig(handlers = [basehdlr], level=logging.INFO) root = logging.getLogger() test.check(root.hasHandlers()) test.check(root.level) test.check(len(root.handlers)) hdlr = root.handlers[0] test.check(hdlr.level) logging.debug("Never gonna give you up") logging.info("Never gonna let you go") logging.warning("Never gonna run around and desert you") logging.error("Never gonna make you cry") root.setLevel(logging.DEBUG) logging.debug("Never gonna give you up") logging.info("Never gonna let you go") logging.warning("Never gonna run around and desert you") logging.error("Never gonna make you cry")
def run(test): """ This tests the buffering handlers which will be important for the AJAX and possibly other loggin handlers. """ resetLogging() thdlr = TestBuffering(test) thdlr.setLevel(2) bufHdlr = BetterBufferingHandler(3) linefmt = logging.Formatter("{levelname}:{message}", style="{") fmt = DemoBufferingFormatter(linefmt) bufHdlr.setFormatter(fmt) bufHdlr.setTarget(thdlr) root = logging.getLogger() root.setLevel(5) root.addHandler(bufHdlr) root.debug("One") root.info("Dos") root.warning("Tres") root.debug("One") root.info("Dos") root.warning("Tres") root.debug("One") root.info("Dos") root.warning("Tres") root.debug("One") root.error("Dos") root.error("Tres")
def console_test(test): """ @note- this test will only generate minimal autotester results but can be manually inspected in the console.log """ resetLogging() logger = logging.getLogger("consoleTest") logger.setLevel(10) hdlr = TestHandler(test, 30) fmt = logging.Formatter("{name}:{message}", style="{") test.check(fmt.usesTime()) hdlr.setFormatter(fmt) hdlr.setLevel(20) logger.addHandler(hdlr) shdlr = logging.StreamHandler() shdlr.setFormatter(fmt) shdlr.setLevel(20) logger.addHandler(shdlr) logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") logger.critical("The house is on fire") shdlr.setLevel(10) logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") logger.critical("The house is on fire") shdlr.setLevel(40) logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") logger.critical("The house is on fire")
def formatter_tests(test): """ This function contains some tests of the formatter objects """ resetLogging() logger = logging.getLogger("fmttest") logger.setLevel(10) hdlr = TestHandler(test, 30) fmt = logging.Formatter("{levelname}:{name}:{message}", style="{") test.check(fmt.usesTime()) hdlr.setFormatter(fmt) logger.addHandler(hdlr) hdlr.setLevel(30) test.check(hdlr.name) hdlr.name = "Asdf" test.check(hdlr.name) test.check(hdlr.level) test.check(logger.hasHandlers()) logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") logger.critical("The house is on fire") hdlr.setLevel(0) logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") logger.critical("The house is on fire")
def logging_api_tests(test): resetLogging() logger = logging.getLogger() logger.setLevel(20) hdlr = TestHandler(test, 30) fmt = logging.Formatter(style="{") hdlr.setFormatter(fmt) logger.addHandler(hdlr) logging.critical("Another Crazy Message!") logging.error("Oh the humanity") logging.warning("Is it hot in here?") logging.info("Big Bird says Hello!") logging.debug("No body gonna see this message") logger.setLevel(40) logging.critical("Another Crazy Message!") logging.error("Oh the humanity") logging.warning("Is it hot in here?") logging.info("Big Bird says Hello!") logging.debug("No body gonna see this message") hdlr.setLevel(20) logging.critical("Another Crazy Message!") logging.error("Oh the humanity") logging.warning("Is it hot in here?") logging.info("Big Bird says Hello!") logging.debug("No body gonna see this message") hdlr.setLevel(39) logging.critical("Another Crazy Message!") logging.error("Oh the humanity") logging.warning("Is it hot in here?") logging.info("Big Bird says Hello!") logging.debug("No body gonna see this message") hdlr.setLevel(41) logging.critical("Another Crazy Message!") logging.error("Oh the humanity") logging.warning("Is it hot in here?") logging.info("Big Bird says Hello!") logging.debug("No body gonna see this message") hdlr.setLevel(40) logging.critical("Another Crazy Message!") logging.error("Oh the humanity") logging.warning("Is it hot in here?") logging.info("Big Bird says Hello!") logging.debug("No body gonna see this message") logger.setLevel(39) logging.critical("Another Crazy Message!") logging.error("Oh the humanity") logging.warning("Is it hot in here?") logging.info("Big Bird says Hello!") logging.debug("No body gonna see this message")
def logger_basics(test): resetLogging() logger = logging.getLogger("tester") test.check(logger.name) test.check(logger.level) test.check(logger.hasHandlers()) # level set methods test.check(logger.getEffectiveLevel()) logger.setLevel(10) test.check(logger.level) testLevel = "USERDEFLEVEL" test.check(test.expectException(lambda: logger.setLevel(testLevel))) test.check(logging.getLevelName(testLevel)) for i in range(0, 50, 5): test.check(logging.getLevelName(i)) logging.addLevelName(35, testLevel) test.check(logging.getLevelName(testLevel)) for i in range(0, 50, 5): test.check(logging.getLevelName(i)) for i in range(0, 50, 5): test.check(logger.isEnabledFor(i)) hdlr = TestHandler(test, 30) fmt = logging.Formatter(style="{") hdlr.setFormatter(fmt) logger.addHandler(hdlr) test.check(logger.hasHandlers()) logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") logger.critical("The house is on fire") logger.setLevel(0) # @note - Transcrypt only has the '.format()' method for # string formatting but python's logging module has a # fixed mode using the old-style % formating concept # this is obviously non-optimal from a testing perspective # as well as form a interop perspective... if __envir__.executor_name == __envir__.transpiler_name: logger.debug("This is a debug msg {}", 1) else: logger.debug("This is a debug msg %d", 1) if __envir__.executor_name == __envir__.transpiler_name: logger.info("This is an info message: {}", "blarg") else: logger.info("This is an info message: %s", "blarg") if __envir__.executor_name == __envir__.transpiler_name: logger.warning("This is a {} warning message in the {}", "blue", "barn") else: logger.warning("This is a %s warning message in the %s", "blue", "barn") if __envir__.executor_name == __envir__.transpiler_name: logger.error("This is an error message: {} {} {}", 3, "23", 4) else: logger.error("This is an error message: %d %s %d", 3, "23", 4) logger.critical("The house is on fire") # Test the handler level change hdlr.setLevel(30) logger.debug("This is a debug msg {}", 1) logger.info("This is an info message: {}", "blarg") if __envir__.executor_name == __envir__.transpiler_name: logger.warning("This is a {} warning message in the {}", "blue", "barn") else: logger.warning("This is a %s warning message in the %s", "blue", "barn") if __envir__.executor_name == __envir__.transpiler_name: logger.error("This is an error message: {} {} {}", 3, "23", 4) else: logger.error("This is an error message: %d %s %d", 3, "23", 4) logger.critical("The house is on fire")
def run(test): """ """ resetLogging() d = { "version" : 1, "formatters": { "fmt1" : { "format": "{levelname}:{asctime}:{name}:{message}", "datefmt": "%H:%M:%S", "style": "{", }, "fmt2" : { "format" : "{name}_{levelname}_{message}", "style": "{", }, "fmt3" : { "()" : TestFormatter, "format" : "[{name}]_{message}", "style" : "{", }, }, "filters" : { "filt1": { '()': TestFilter, 'modulo': 2, }, }, "handlers" : { "hdlr1": { "class": "logging.StreamHandler", #TestHandler, "formatter": "fmt1", "level": "DEBUG", "filters": ["filt1"], }, "hdlr2": { "class" : "utils.TestHandler", "formatter": "fmt2", "filters": [], "level": "WARNING", "test" : test, "lvl" : 1, }, "hdlr3": { "class" : "utils.TestHandler", "formatter": "fmt3", "level": "INFO", "test" : test, "lvl" : 2, }, }, 'root': { 'level': "INFO", 'handlers': ["hdlr1"] }, "loggers": { "test1": { "level": 30, "filters": [], "handlers": ["hdlr2", "hdlr3"], }, } } if __envir__.executor_name == __envir__.transpiler_name: logging.config.addResolvable("utils.TestHandler", TestHandler) logging.config.dictConfig(d) tlog = logging.getLogger("test1") test.check( len(tlog.handlers) ) test.check( len(tlog.filters) ) test.check( tlog.level ) for i in range(0, 10): logging.debug("1234") logging.info("asdf") logging.warning("ioureoiu") logging.error("jekwejrjek") logging.critical("jlkjelkjwelkr") tlog.debug("1234") tlog.info("asdf") tlog.warning("ioureoiu") tlog.error("jekwejrjek") tlog.critical("jlkjelkjwelkr")
def logger_basics(test): resetLogging() logger = logging.getLogger("tester") test.check(logger.name) test.check(logger.level) test.check(logger.hasHandlers()) # level set methods test.check(logger.getEffectiveLevel()) logger.setLevel(10) test.check(logger.level) testLevel = "USERDEFLEVEL" test.check(test.expectException(lambda : logger.setLevel(testLevel))) test.check(logging.getLevelName(testLevel)) for i in range(0,50,5): test.check(logging.getLevelName(i)) logging.addLevelName(35, testLevel) test.check(logging.getLevelName(testLevel)) for i in range(0,50,5): test.check(logging.getLevelName(i)) for i in range(0,50,5): test.check(logger.isEnabledFor(i)) hdlr = TestHandler(test, 30) fmt = logging.Formatter(style="{") hdlr.setFormatter(fmt) logger.addHandler(hdlr) test.check(logger.hasHandlers()) logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") logger.critical("The house is on fire") logger.setLevel(0) # @note - Transcrypt only has the '.format()' method for # string formatting but python's logging module has a # fixed mode using the old-style % formating concept # this is obviously non-optimal from a testing perspective # as well as form a interop perspective... if __envir__.executor_name == __envir__.transpiler_name: logger.debug("This is a debug msg {}", 1) else: logger.debug("This is a debug msg %d", 1) if __envir__.executor_name == __envir__.transpiler_name: logger.info("This is an info message: {}", "blarg") else: logger.info("This is an info message: %s", "blarg") if __envir__.executor_name == __envir__.transpiler_name: logger.warning("This is a {} warning message in the {}", "blue", "barn") else: logger.warning("This is a %s warning message in the %s", "blue", "barn") if __envir__.executor_name == __envir__.transpiler_name: logger.error("This is an error message: {} {} {}", 3, "23", 4) else: logger.error("This is an error message: %d %s %d", 3, "23", 4) logger.critical("The house is on fire") # Test the handler level change hdlr.setLevel(30) logger.debug("This is a debug msg {}", 1) logger.info("This is an info message: {}", "blarg") if __envir__.executor_name == __envir__.transpiler_name: logger.warning("This is a {} warning message in the {}", "blue", "barn") else: logger.warning("This is a %s warning message in the %s", "blue", "barn") if __envir__.executor_name == __envir__.transpiler_name: logger.error("This is an error message: {} {} {}", 3, "23", 4) else: logger.error("This is an error message: %d %s %d", 3, "23", 4) logger.critical("The house is on fire")