How to use logzero - 10 common examples

To help you get started, we’ve selected a few logzero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metachris / logzero / tests / test_logzero.py View on Github external
def test_multiple_loggers_one_logfile():
    """
    Should properly log bytes
    """
    logzero.reset_default_logger()
    temp = tempfile.NamedTemporaryFile()
    try:
        logger1 = logzero.setup_logger(name="logger1", logfile=temp.name)
        logger2 = logzero.setup_logger(name="logger2", logfile=temp.name)
        logger3 = logzero.setup_logger(name="logger3", logfile=temp.name)

        logger1.info("logger1")
        logger2.info("logger2")
        logger3.info("logger3")

        with open(temp.name) as f:
            content = f.read().strip()
            assert "logger1" in content
            assert "logger2" in content
            assert "logger3" in content
            assert len(content.split("\n")) == 3
github jerrylizilong / autotest_platform / app / core / log.py View on Github external
def __init__(self) :
        self.logfile = os.path.join(config.logPath, 'core-service.log')
        logzero.logfile(self.logfile, maxBytes = 1e6, backupCount = 3)
        import logging
        formatter = logging.Formatter('%(asctime)-15s - [%(filename)s: %(lineno)s] -%(levelname)s: %(message)s');
        logzero.formatter(formatter)
        logzero.loglevel(logging.INFO)
        self.logger = logzero.logger
github metachris / logzero / tests / test_logzero.py View on Github external
def test_bytes():
    """
    Should properly log bytes
    """
    logzero.reset_default_logger()
    temp = tempfile.NamedTemporaryFile()
    try:
        logger = logzero.setup_logger(logfile=temp.name)

        testbytes = os.urandom(20)
        logger.debug(testbytes)
        logger.debug(None)

        # with open(temp.name) as f:
        #     content = f.read()
        #     # assert str(testbytes) in content

    finally:
        temp.close()
github metachris / logzero / tests / test_logzero.py View on Github external
"""
    logzero.reset_default_logger()
    temp = tempfile.NamedTemporaryFile()
    try:
        logzero.setup_default_logger(logfile=temp.name, disableStderrLogger=disableStdErrorLogger)
        logzero.logger.debug("debug1")  # will be logged

        # Reconfigure with loglevel INFO
        logzero.setup_default_logger(logfile=temp.name, level=logging.INFO, disableStderrLogger=disableStdErrorLogger)
        logzero.logger.debug("debug2")  # will not be logged
        logzero.logger.info("info1")  # will be logged

        # Reconfigure with a different formatter
        log_format = '%(color)s[xxx]%(end_color)s %(message)s'
        formatter = logzero.LogFormatter(fmt=log_format)
        logzero.setup_default_logger(logfile=temp.name, level=logging.INFO, formatter=formatter, disableStderrLogger=disableStdErrorLogger)

        logzero.logger.info("info2")  # will be logged with new formatter
        logzero.logger.debug("debug3")  # will not be logged

        with open(temp.name) as f:
            content = f.read()
            test_default_logger_output(content)

    finally:
        temp.close()
github metachris / logzero / tests / test_logzero.py View on Github external
def test_default_logger(disableStdErrorLogger=False):
    """
    Default logger should work and be able to be reconfigured.
    """
    logzero.reset_default_logger()
    temp = tempfile.NamedTemporaryFile()
    try:
        logzero.setup_default_logger(logfile=temp.name, disableStderrLogger=disableStdErrorLogger)
        logzero.logger.debug("debug1")  # will be logged

        # Reconfigure with loglevel INFO
        logzero.setup_default_logger(logfile=temp.name, level=logging.INFO, disableStderrLogger=disableStdErrorLogger)
        logzero.logger.debug("debug2")  # will not be logged
        logzero.logger.info("info1")  # will be logged

        # Reconfigure with a different formatter
        log_format = '%(color)s[xxx]%(end_color)s %(message)s'
        formatter = logzero.LogFormatter(fmt=log_format)
        logzero.setup_default_logger(logfile=temp.name, level=logging.INFO, formatter=formatter, disableStderrLogger=disableStdErrorLogger)

        logzero.logger.info("info2")  # will be logged with new formatter
        logzero.logger.debug("debug3")  # will not be logged

        with open(temp.name) as f:
            content = f.read()
            test_default_logger_output(content)

    finally:
github metachris / logzero / tests / test_logzero.py View on Github external
def test_default_logger(disableStdErrorLogger=False):
    """
    Default logger should work and be able to be reconfigured.
    """
    logzero.reset_default_logger()
    temp = tempfile.NamedTemporaryFile()
    try:
        logzero.setup_default_logger(logfile=temp.name, disableStderrLogger=disableStdErrorLogger)
        logzero.logger.debug("debug1")  # will be logged

        # Reconfigure with loglevel INFO
        logzero.setup_default_logger(logfile=temp.name, level=logging.INFO, disableStderrLogger=disableStdErrorLogger)
        logzero.logger.debug("debug2")  # will not be logged
        logzero.logger.info("info1")  # will be logged

        # Reconfigure with a different formatter
        log_format = '%(color)s[xxx]%(end_color)s %(message)s'
        formatter = logzero.LogFormatter(fmt=log_format)
        logzero.setup_default_logger(logfile=temp.name, level=logging.INFO, formatter=formatter, disableStderrLogger=disableStdErrorLogger)

        logzero.logger.info("info2")  # will be logged with new formatter
        logzero.logger.debug("debug3")  # will not be logged

        with open(temp.name) as f:
github jerrylizilong / autotest_platform / app / log.py View on Github external
def __init__(self) :
        self.logfile = os.path.join(config.logPath, 'flask.log')
        logzero.logfile(self.logfile, maxBytes = 1e6, backupCount = 3)
        import logging
        formatter = logging.Formatter('%(asctime)-15s - [%(filename)s: %(lineno)s] -%(levelname)s: %(message)s');
        logzero.formatter(formatter)
        logzero.loglevel(logging.ERROR)
        self.logger = logzero.logger