Python logging.NOTSET Examples

The following are 30 code examples for showing how to use logging.NOTSET(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module logging , or try the search function .

Example 1
Project: CAMISIM   Author: CAMI-challenge   File: loggingwrapper.py    License: Apache License 2.0 6 votes vote down vote up
def set_level(self, level):
		"""
		Set the minimum level of messages to be logged.

		Level of Log Messages
		CRITICAL	50
		ERROR	40
		WARNING	30
		INFO	20
		DEBUG	10
		NOTSET	0

		@param level: minimum level of messages to be logged
		@type level: int or long

		@return: None
		@rtype: None
		"""
		assert level in self._levelNames

		list_of_handlers = self._logger.handlers
		for handler in list_of_handlers:
			handler.setLevel(level) 
Example 2
Project: CAMISIM   Author: CAMI-challenge   File: loggingwrapper.py    License: Apache License 2.0 6 votes vote down vote up
def set_level(self, level):
        """
        Set the minimum level of messages to be logged.

        Level of Log Messages
        CRITICAL    50
        ERROR    40
        WARNING    30
        INFO    20
        DEBUG    10
        NOTSET    0

        @param level: minimum level of messages to be logged
        @type level: int or long

        @return: None
        @rtype: None
        """
        assert level in self._levelNames

        list_of_handlers = self._logger.handlers
        for handler in list_of_handlers:
            handler.setLevel(level) 
Example 3
Project: jawfish   Author: war-and-code   File: config.py    License: MIT License 6 votes vote down vote up
def _handle_existing_loggers(existing, child_loggers, disable_existing):
    """
    When (re)configuring logging, handle loggers which were in the previous
    configuration but are not in the new configuration. There's no point
    deleting them as other threads may continue to hold references to them;
    and by disabling them, you stop them doing any logging.

    However, don't disable children of named loggers, as that's probably not
    what was intended by the user. Also, allow existing loggers to NOT be
    disabled if disable_existing is false.
    """
    root = logging.root
    for log in existing:
        logger = root.manager.loggerDict[log]
        if log in child_loggers:
            logger.level = logging.NOTSET
            logger.handlers = []
            logger.propagate = True
        else:
            logger.disabled = disable_existing 
Example 4
Project: recruit   Author: Frank-qlu   File: logging.py    License: Apache License 2.0 6 votes vote down vote up
def create_logger(app):
    """Get the ``'flask.app'`` logger and configure it if needed.

    When :attr:`~flask.Flask.debug` is enabled, set the logger level to
    :data:`logging.DEBUG` if it is not set.

    If there is no handler for the logger's effective level, add a
    :class:`~logging.StreamHandler` for
    :func:`~flask.logging.wsgi_errors_stream` with a basic format.
    """
    logger = logging.getLogger('flask.app')

    if app.debug and logger.level == logging.NOTSET:
        logger.setLevel(logging.DEBUG)

    if not has_level_handler(logger):
        logger.addHandler(default_handler)

    return logger 
Example 5
Project: jbox   Author: jpush   File: log.py    License: MIT License 6 votes vote down vote up
def log(self, level, msg, *args, **kwargs):
        """Delegate a log call to the underlying logger.

        The level here is determined by the echo
        flag as well as that of the underlying logger, and
        logger._log() is called directly.

        """

        # inline the logic from isEnabledFor(),
        # getEffectiveLevel(), to avoid overhead.

        if self.logger.manager.disable >= level:
            return

        selected_level = self._echo_map[self.echo]
        if selected_level == logging.NOTSET:
            selected_level = self.logger.getEffectiveLevel()

        if level >= selected_level:
            self.logger._log(level, msg, args, **kwargs) 
Example 6
Project: jbox   Author: jpush   File: core.py    License: MIT License 6 votes vote down vote up
def  set_logging(self, level):
        level_list= ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]
        if level in level_list:
            if(level == "CRITICAL"):
                logging.basicConfig(level=logging.CRITICAL)
            if (level == "ERROR"):
                logging.basicConfig(level=logging.ERROR)
            if (level == "WARNING"):
                logging.basicConfig(level=logging.WARNING)
            if (level == "INFO"):
                logging.basicConfig(level=logging.INFO)
            if (level == "DEBUG"):
                logging.basicConfig(level=logging.DEBUG)
            if (level == "NOTSET"):
                logging.basicConfig(level=logging.NOTSET)
        else:
            print ("set logging level failed ,the level is invalid.") 
Example 7
Project: ungoogled-chromium   Author: Eloston   File: _common.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_logger(initial_level=logging.INFO):
    """Gets the named logger"""

    logger = logging.getLogger(LOGGER_NAME)

    if logger.level == logging.NOTSET:
        logger.setLevel(initial_level)

        if not logger.hasHandlers():
            console_handler = logging.StreamHandler()
            console_handler.setLevel(initial_level)

            format_string = '%(levelname)s: %(message)s'
            formatter = logging.Formatter(format_string)
            console_handler.setFormatter(formatter)

            logger.addHandler(console_handler)
    return logger 
Example 8
Project: koku   Author: project-koku   File: test_azure_report_processor.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_azure_process(self):
        """Test the processing of an uncompressed Azure file."""
        counts = {}

        report_db = self.accessor
        report_schema = report_db.report_schema
        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            with schema_context(self.schema):
                count = table.objects.count()
            counts[table_name] = count
        logging.disable(logging.NOTSET)  # We are currently disabling all logging below CRITICAL in masu/__init__.py
        with self.assertLogs("masu.processor.azure.azure_report_processor", level="INFO") as logger:
            self.processor.process()
            self.assertIn("INFO:masu.processor.azure.azure_report_processor", logger.output[0])
            self.assertIn("costreport_a243c6f2-199f-4074-9a2c-40e671cf1584.csv", logger.output[0])

        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            with schema_context(self.schema):
                count = table.objects.count()
            self.assertTrue(count > counts[table_name])
        self.assertFalse(os.path.exists(self.test_report)) 
Example 9
Project: faces   Author: skarlekar   File: _logging.py    License: GNU General Public License v2.0 6 votes vote down vote up
def setLevel(level):
    """Set logging level for the main logger."""
    level = level.lower().strip()
    imdbpyLogger.setLevel(LEVELS.get(level, logging.NOTSET))
    imdbpyLogger.log(imdbpyLogger.level, 'set logging threshold to "%s"',
                    logging.getLevelName(imdbpyLogger.level))


#imdbpyLogger.setLevel(logging.DEBUG)


# It can be an idea to have a single function to log and warn:
#import warnings
#def log_and_warn(msg, args=None, logger=None, level=None):
#    """Log the message and issue a warning."""
#    if logger is None:
#        logger = imdbpyLogger
#    if level is None:
#        level = logging.WARNING
#    if args is None:
#        args = ()
#    #warnings.warn(msg % args, stacklevel=0)
#    logger.log(level, msg % args) 
Example 10
Project: ITDD   Author: lizekang   File: logging.py    License: MIT License 6 votes vote down vote up
def init_logger(log_file=None, log_file_level=logging.NOTSET):
    log_format = logging.Formatter("[%(asctime)s %(levelname)s] %(message)s")
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    console_handler = logging.StreamHandler()
    console_handler.setFormatter(log_format)
    logger.handlers = [console_handler]

    if log_file and log_file != '':
        file_handler = logging.FileHandler(log_file)
        file_handler.setLevel(log_file_level)
        file_handler.setFormatter(log_format)
        logger.addHandler(file_handler)

    return logger 
Example 11
Project: python-sdk   Author: optimizely   File: test_logger.py    License: Apache License 2.0 6 votes vote down vote up
def test_adapt_logger__noop(self):
        """Test that adapt_logger returns a standard python logger from a NoOpLogger."""
        noop_logger = _logger.NoOpLogger()
        standard_logger = _logger.adapt_logger(noop_logger)

        # adapt_logger knows about the loggers attached to this class.
        self.assertIs(noop_logger.logger, standard_logger)

        # Verify properties of the logger
        self.assertIsInstance(standard_logger, logging.Logger)
        self.assertEqual('optimizely.logger.NoOpLogger', standard_logger.name)
        self.assertEqual(logging.NOTSET, standard_logger.level)

        # Should have a single NullHandler (with a default formatter).
        self.assertEqual(1, len(standard_logger.handlers))
        handler = standard_logger.handlers[0]
        self.assertIsInstance(handler, logging.NullHandler)
        self.assertEqual(
            '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s', handler.formatter._fmt,
        ) 
Example 12
Project: nata   Author: GoLP-IST   File: comfort.py    License: MIT License 6 votes vote down vote up
def activate_logging(loggin_level: str = "info"):
    import logging

    if loggin_level == "notset":
        level = logging.NOTSET
    elif loggin_level == "debug":
        level = logging.DEBUG
    elif loggin_level == "info":
        level = logging.INFO
    elif loggin_level == "warning":
        level = logging.WARNING
    elif loggin_level == "error":
        level = logging.ERROR
    elif loggin_level == "critical":
        level = logging.CRITICAL
    else:
        raise ValueError(
            "Invalid loggin level provided! "
            + "Allowed are 'notset', 'debug', 'info', 'warning', 'error', "
            + "and 'critical'!"
        )

    logging.basicConfig(format="%(levelname)s :: %(message)s", level=level) 
Example 13
Project: airflow   Author: apache   File: test_logging_config.py    License: Apache License 2.0 6 votes vote down vote up
def reset_logging():
    """Reset Logging"""
    manager = logging.root.manager
    manager.disabled = logging.NOTSET
    airflow_loggers = [
        logger for logger_name, logger in manager.loggerDict.items() if logger_name.startswith('airflow')
    ]
    for logger in airflow_loggers:  # pylint: disable=too-many-nested-blocks
        if isinstance(logger, logging.Logger):
            logger.setLevel(logging.NOTSET)
            logger.propagate = True
            logger.disabled = False
            logger.filters.clear()
            handlers = logger.handlers.copy()
            for handler in handlers:
                # Copied from `logging.shutdown`.
                try:
                    handler.acquire()
                    handler.flush()
                    handler.close()
                except (OSError, ValueError):
                    pass
                finally:
                    handler.release()
                logger.removeHandler(handler) 
Example 14
Project: clickhouse-mysql-data-reader   Author: Altinity   File: clioptions.py    License: MIT License 6 votes vote down vote up
def log_level_from_string(log_level_string):
        """Convert string representation of a log level into logging.XXX constant"""

        if isinstance(log_level_string, str):
            level = log_level_string.upper()

            if level == 'CRITICAL':
                return logging.CRITICAL
            if level == 'ERROR':
                return logging.ERROR
            if level == 'WARNING':
                return logging.WARNING
            if level == 'INFO':
                return logging.INFO
            if level == 'DEBUG':
                return logging.DEBUG
            if level == 'NOTSET':
                return logging.NOTSET

        return logging.NOTSET 
Example 15
Project: Multi-Label-Text-Classification-for-Chinese   Author: hscspring   File: utils.py    License: MIT License 6 votes vote down vote up
def init_logger(log_file=None, log_file_level=logging.NOTSET):
    if isinstance(log_file, Path):
        log_file = str(log_file)

    log_format = logging.Formatter("%(message)s")
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    console_handler = logging.StreamHandler()
    console_handler.setFormatter(log_format)
    logger.handlers = [console_handler]
    if log_file:
        file_handler = logging.FileHandler(log_file)
        file_handler.setLevel(log_file_level)
        file_handler.setFormatter(log_format)
        logger.addHandler(file_handler)
    return logger 
Example 16
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: common.py    License: Apache License 2.0 5 votes vote down vote up
def default_logger():
    """A logger used to output seed information to nosetests logs."""
    logger = logging.getLogger(__name__)
    # getLogger() lookups will return the same logger, but only add the handler once.
    if not len(logger.handlers):
        handler = logging.StreamHandler(sys.stderr)
        handler.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
        logger.addHandler(handler)
        if (logger.getEffectiveLevel() == logging.NOTSET):
            logger.setLevel(logging.INFO)
    return logger 
Example 17
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: common.py    License: Apache License 2.0 5 votes vote down vote up
def default_logger():
    """A logger used to output seed information to nosetests logs."""
    logger = logging.getLogger(__name__)
    # getLogger() lookups will return the same logger, but only add the handler once.
    if not len(logger.handlers):
        handler = logging.StreamHandler(sys.stderr)
        handler.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
        logger.addHandler(handler)
        if (logger.getEffectiveLevel() == logging.NOTSET):
            logger.setLevel(logging.INFO)
    return logger 
Example 18
Project: qutebrowser   Author: qutebrowser   File: logfail.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, level=logging.NOTSET, min_level=logging.WARNING):
        self._min_level = min_level
        super().__init__(level) 
Example 19
Project: qutebrowser   Author: qutebrowser   File: test_log.py    License: GNU General Public License v3.0 5 votes vote down vote up
def test_ram_handler(logger, data, expected):
    handler = log.RAMHandler(capacity=2)
    handler.setLevel(logging.NOTSET)
    logger.addHandler(handler)

    for line in data:
        logger.debug(line)

    assert [rec.msg for rec in handler._data] == expected
    assert handler.dump_log() == '\n'.join(expected) 
Example 20
Project: qutebrowser   Author: qutebrowser   File: log.py    License: GNU General Public License v3.0 5 votes vote down vote up
def init_log(args: argparse.Namespace) -> None:
    """Init loggers based on the argparse namespace passed."""
    level = (args.loglevel or "info").upper()
    try:
        numeric_level = getattr(logging, level)
    except AttributeError:
        raise ValueError("Invalid log level: {}".format(args.loglevel))

    if numeric_level > logging.DEBUG and args.debug:
        numeric_level = logging.DEBUG

    console, ram = _init_handlers(numeric_level, args.color, args.force_color,
                                  args.json_logging, args.loglines)
    root = logging.getLogger()
    global console_filter
    if console is not None:
        console_filter = LogFilter.parse(args.logfilter)
        console.addFilter(console_filter)
        root.addHandler(console)
    if ram is not None:
        root.addHandler(ram)
    else:
        # If we add no handler, we shouldn't process non visible logs at all
        #
        # disable blocks the current level (while setHandler shows the current
        # level), so -1 to avoid blocking handled messages.
        logging.disable(numeric_level - 1)

    global _log_inited, _args
    _args = args
    root.setLevel(logging.NOTSET)
    logging.captureWarnings(True)
    _init_py_warnings()
    QtCore.qInstallMessageHandler(qt_message_handler)
    _log_inited = True 
Example 21
Project: maubot   Author: maubot   File: log.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, level=logging.NOTSET) -> None:
        super().__init__(level)
        self.lines = deque(maxlen=MAX_LINES)
        self.formatter = logging.Formatter()
        self.listeners = [] 
Example 22
Project: modelforge   Author: src-d   File: slogging.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, level=logging.NOTSET):
        """Initialize a new StructuredHandler."""
        super().__init__(level)
        self.local = threading.local() 
Example 23
Project: recruit   Author: Frank-qlu   File: _internal.py    License: Apache License 2.0 5 votes vote down vote up
def _log(type, message, *args, **kwargs):
    """Log into the internal werkzeug logger."""
    global _logger
    if _logger is None:
        import logging

        _logger = logging.getLogger("werkzeug")
        if _logger.level == logging.NOTSET:
            _logger.setLevel(logging.INFO)
        # Only set up a default log handler if the
        # end-user application didn't set anything up.
        if not logging.root.handlers:
            handler = logging.StreamHandler()
            _logger.addHandler(handler)
    getattr(_logger, type)(message.rstrip(), *args, **kwargs) 
Example 24
Project: jbox   Author: jpush   File: log.py    License: MIT License 5 votes vote down vote up
def getEffectiveLevel(self):
        """What's the effective level for this logger?"""

        level = self._echo_map[self.echo]
        if level == logging.NOTSET:
            level = self.logger.getEffectiveLevel()
        return level 
Example 25
Project: jbox   Author: jpush   File: _internal.py    License: MIT License 5 votes vote down vote up
def _log(type, message, *args, **kwargs):
    """Log into the internal werkzeug logger."""
    global _logger
    if _logger is None:
        import logging
        _logger = logging.getLogger('werkzeug')
        # Only set up a default log handler if the
        # end-user application didn't set anything up.
        if not logging.root.handlers and _logger.level == logging.NOTSET:
            _logger.setLevel(logging.INFO)
            handler = logging.StreamHandler()
            _logger.addHandler(handler)
    getattr(_logger, type)(message.rstrip(), *args, **kwargs) 
Example 26
Project: simple-effective-text-matching-pytorch   Author: alibaba-edu   File: logger.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, level=logging.NOTSET):
        super().__init__(level) 
Example 27
Project: alienfx   Author: trackmastersteve   File: logger.py    License: GNU General Public License v3.0 5 votes vote down vote up
def set_logfile(path):
    """ Set a log file to print logs to. By default, no logs are printed to 
    file. If a log file is set, then all levels of log messages are enabled 
    and sent to it.
    """
    logging.disable(logging.NOTSET)
    logging.basicConfig(
        filename=os.path.expanduser(path), 
        filemode="w",
        level=logging.NOTSET, 
        )#format="%(levelname)s:%(module)s:%(lineno)d:%(message)s") 
Example 28
Project: sea   Author: shanbay   File: app.py    License: MIT License 5 votes vote down vote up
def logger(self):
        logger = logging.getLogger('sea.app')
        if self.debug and logger.level == logging.NOTSET:
            logger.setLevel(logging.DEBUG)
        if not utils.logger_has_level_handler(logger):
            h = logging.StreamHandler()
            h.setFormatter(logging.Formatter('%(message)s'))
            logger.addHandler(h)
        return logger 
Example 29
Project: mishkal   Author: linuxscout   File: anasem.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, cache_path=False):
        
        self.semdict = semdictionary.SemanticDictionary()
        
        # a NoSql database for ferquent relationship between lexical words.
        self.syncache = aranasyn.cache.cache(cache_path)
        logging.basicConfig(level=logging.NOTSET)
        self.logger = logging.getLogger(__name__) 
Example 30
Project: covimerage   Author: Vimjas   File: logger.py    License: MIT License 5 votes vote down vote up
def __init__(self, level=logging.NOTSET):
        logging.Handler.__init__(self, level)