diff --git a/README.md b/README.md index ebdfccc..3e7ff04 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,11 @@ Changes in ``pynose`` from legacy ``nose`` include: * Fixes "DeprecationWarning: pkg_resources is deprecated as an API." * Fixes all ``flake8`` issues from the original ``nose``. * Replaces the ``imp`` module with the newer ``importlib`` module. -* The default logging level now hides "debug" logs for less noise. +* The default logging level now hides `"INFO"` logs for less noise. +* Adds ``--capture-logs`` for hiding output from all logging levels. +* Adds ``--logging-init`` to use ``logging.basicConfig(level)``. * The ``-s`` option is always active to see the output of ``print()``. +* Adds ``--capture-output`` for hiding the output of ``print()``. * Adds ``--co`` as a shortcut to using ``--collect-only``. -------- @@ -363,9 +366,11 @@ Options Clear all other logging handlers ---logging-level=DEFAULT +--logging-level=LEVEL - Set the log level to capture + Set the log level to capture. (Default: "WARNING") + Levels: ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] + You may need to include `--logging-init` to change the default. --with-coverage @@ -547,4 +552,15 @@ Options Enable capturing output. This hides the output of print(). (os.environ["NOSE_CAPTURE"] = "1") + +--capture-logs, --capture_logs + + Enable capturing logs. This hides output from all log levels. + (os.environ["NOSE_CAPTURELOGS"] = "1") + +--logging-init + + Using this will call `logging.basicConfig(level)`, which may + be needed if you're trying to change the default logging level + with `--logging-level=LEVEL`. ``` diff --git a/nose/__version__.py b/nose/__version__.py index 066d68c..8aaa138 100755 --- a/nose/__version__.py +++ b/nose/__version__.py @@ -1,2 +1,2 @@ # pynose nose package -__version__ = "1.5.0" +__version__ = "1.5.1" diff --git a/nose/plugins/logcapture.py b/nose/plugins/logcapture.py index 70b3eec..16af67e 100644 --- a/nose/plugins/logcapture.py +++ b/nose/plugins/logcapture.py @@ -12,6 +12,7 @@ You can remove other installed logging handlers with the ``--logging-clear-handlers`` option.""" import logging +import os import threading from logging import Handler from nose.plugins.base import Plugin @@ -115,6 +116,18 @@ def options(self, parser, env): help="Disable logging capture plugin. " "Logging configuration will be left intact." " [NOSE_NOLOGCAPTURE]") + parser.add_option( + "--capture-logs", "--capture_logs", action="store_true", + default=0, dest="capture_logs", + help="Enable logging capture plugin. " + "Logging configuration will be left intact." + " [NOSE_CAPTURELOGS]") + parser.add_option( + "--logging-init", action="store_true", + default=0, dest="logging_init", + help="Initialize standard logging configuration with:\n" + "logging.basicConfig(level)\n" + " [NOSE_LOGINIT]") parser.add_option( "--logging-format", action="store", dest="logcapture_format", default=env.get('NOSE_LOGFORMAT') or self.logformat, @@ -149,18 +162,28 @@ def options(self, parser, env): help="Clear all other logging handlers") parser.add_option( "--logging-level", action="store", - default='NOTSET', dest="logcapture_level", + default='WARNING', dest="logcapture_level", help="Set the log level to capture") def configure(self, options, conf): """Configure plugin.""" self.conf = conf - if not options.logcapture or conf.loggingConfig: - self.enabled = False self.logformat = options.logcapture_format self.logdatefmt = options.logcapture_datefmt self.clear = options.logcapture_clear self.loglevel = options.logcapture_level + if not options.logcapture or conf.loggingConfig: + self.enabled = False + if ( + "NOSE_CAPTURELOGS" in os.environ + and os.environ["NOSE_CAPTURELOGS"] == "1" + ) or options.capture_logs: + self.enabled = True + if ( + "NOSE_LOGINIT" in os.environ + and os.environ["NOSE_LOGINIT"] == "1" + ) or options.logging_init: + logging.basicConfig(level=self.loglevel) if options.logcapture_filters: self.filters = options.logcapture_filters.split(',')