From 526e30be14332d32dccf275d89fd8bd69307dfbf Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 13 Apr 2017 13:07:04 -0500 Subject: [PATCH 1/5] Document logging functionality. --- doc/misc.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/misc.rst b/doc/misc.rst index a30092f6..a6748445 100644 --- a/doc/misc.rst +++ b/doc/misc.rst @@ -19,6 +19,22 @@ and say:: In addition, you need to have :mod:`numpy` installed. +Logging +======= + +Logging output for scripts that use :mod:`pytential` may be controlled through +the environment variables ``PYTENTIAL_LOG_`` + *log_level*. Each variable accepts a +colon-separated list of module names that set the logging level for the given +module. Example usage:: + + PYTENTIAL_LOG_DEBUG=pytential:loopy PYTENTIAL_LOG_INFO=boxtree python test.py + +This sets the logging level of :mod:`pytential` and :mod:`loopy` to +:attr:`logging.DEBUG`, and the logging level of :mod:`boxtree` to +:attr:`logging.INFO`. + +Note: This feature is incompatible with :func:`logging.basicConfig()`. + User-visible Changes ==================== -- GitLab From 20409a4754f0d9be8f2c256922e88e52a6910f4f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 13 Apr 2017 13:07:16 -0500 Subject: [PATCH 2/5] Add logging control for all predefined logging levels. --- pytential/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pytential/__init__.py b/pytential/__init__.py index 5d8c61fc..98e62c71 100644 --- a/pytential/__init__.py +++ b/pytential/__init__.py @@ -30,25 +30,25 @@ from pytential.symbolic.execution import bind from pytools import memoize_on_first_arg -import os - -PYTENTIAL_LOG_DEBUG = os.environ.get("PYTENTIAL_LOG_DEBUG") - - -if PYTENTIAL_LOG_DEBUG is not None: +def _set_up_logging_from_environment(): import logging + import os from pytential.log import set_up_logging - set_up_logging(PYTENTIAL_LOG_DEBUG.split(":"), level=logging.DEBUG) + for level_name, level in ( + ("DEBUG", logging.DEBUG), + ("INFO", logging.INFO), + ("WARNING", logging.WARNING), + ("ERROR", logging.ERROR), + ("CRITICAL", logging.CRITICAL)): -PYTENTIAL_LOG_INFO = os.environ.get("PYTENTIAL_LOG_INFO") + pytential_log_var = os.environ.get("PYTENTIAL_LOG_%s" % level_name) + if pytential_log_var is not None: + set_up_logging(pytential_log_var.split(":"), level=level) -if PYTENTIAL_LOG_INFO is not None: - import logging - from pytential.log import set_up_logging - set_up_logging(PYTENTIAL_LOG_INFO.split(":"), level=logging.INFO) +_set_up_logging_from_environment() @memoize_on_first_arg -- GitLab From 96fd676e9ab7fe75e8839de36ad3c193c6d53ac0 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 13 Apr 2017 13:14:00 -0500 Subject: [PATCH 3/5] Fix a sentence that made no sense. --- doc/misc.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/misc.rst b/doc/misc.rst index a6748445..32561a21 100644 --- a/doc/misc.rst +++ b/doc/misc.rst @@ -23,9 +23,9 @@ Logging ======= Logging output for scripts that use :mod:`pytential` may be controlled through -the environment variables ``PYTENTIAL_LOG_`` + *log_level*. Each variable accepts a -colon-separated list of module names that set the logging level for the given -module. Example usage:: +the environment variables ``PYTENTIAL_LOG_`` + *log_level*. The variable for the +desired level should be set to a colon-separated list of module names. Example +usage:: PYTENTIAL_LOG_DEBUG=pytential:loopy PYTENTIAL_LOG_INFO=boxtree python test.py -- GitLab From 77dbca3a53e6e52bfb0fcea2126b4700a30b871f Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 13 Apr 2017 13:16:43 -0500 Subject: [PATCH 4/5] More wording updates. --- doc/misc.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/misc.rst b/doc/misc.rst index 32561a21..c982ab5e 100644 --- a/doc/misc.rst +++ b/doc/misc.rst @@ -22,10 +22,10 @@ In addition, you need to have :mod:`numpy` installed. Logging ======= -Logging output for scripts that use :mod:`pytential` may be controlled through -the environment variables ``PYTENTIAL_LOG_`` + *log_level*. The variable for the -desired level should be set to a colon-separated list of module names. Example -usage:: +Logging output for scripts that use :mod:`pytential` may be controlled on a +per-module basis through the environment variables ``PYTENTIAL_LOG_`` + +*log_level*. The variable for the desired level should be set to a +colon-separated list of module names. Example usage:: PYTENTIAL_LOG_DEBUG=pytential:loopy PYTENTIAL_LOG_INFO=boxtree python test.py -- GitLab From 2163eb1d0c28139dcfe0c716f08283ba033cfbf2 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 13 Apr 2017 13:24:49 -0500 Subject: [PATCH 5/5] Change installation and logging to be sub-sections of Installation and Usage. --- doc/misc.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/misc.rst b/doc/misc.rst index c982ab5e..467b3d78 100644 --- a/doc/misc.rst +++ b/doc/misc.rst @@ -1,5 +1,8 @@ +Installation and Usage +====================== + Installation -============ +------------ This command should install :mod:`pytential`:: @@ -20,7 +23,7 @@ and say:: In addition, you need to have :mod:`numpy` installed. Logging -======= +------- Logging output for scripts that use :mod:`pytential` may be controlled on a per-module basis through the environment variables ``PYTENTIAL_LOG_`` + -- GitLab