Skip to content

Commit

Permalink
Merge pull request #24 from mdmintz/logging-optimizations
Browse files Browse the repository at this point in the history
Logging Optimizations
  • Loading branch information
mdmintz authored Mar 22, 2024
2 parents 12eda10 + fb5a677 commit 3c5da5c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

--------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`.
```
2 changes: 1 addition & 1 deletion nose/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# pynose nose package
__version__ = "1.5.0"
__version__ = "1.5.1"
29 changes: 26 additions & 3 deletions nose/plugins/logcapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(',')

Expand Down

0 comments on commit 3c5da5c

Please sign in to comment.