diff --git a/dune/xt/common/bindings.cc b/dune/xt/common/bindings.cc index 45b8311724fabecda943be0031705a5becee463d..d03bcb9e12043197493f7ea7d70fbcb4ff439af9 100644 --- a/dune/xt/common/bindings.cc +++ b/dune/xt/common/bindings.cc @@ -67,14 +67,28 @@ PYBIND11_PLUGIN(_common) Dune::XT::Common::TimedLogger().create( max_info_level, max_debug_level, enable_warnings, enable_colors, info_color, debug_color, warning_color); }, - "max_info_level"_a = -1, - "max_debug_level"_a = -1, + "max_info_level"_a = std::numeric_limits<ssize_t>::max(), + "max_debug_level"_a = std::numeric_limits<ssize_t>::max(), "enable_warnings"_a = true, "enable_colors"_a = true, "info_color"_a = "blue", "debug_color"_a = "darkgray", "warning_color"_a = "red"); + m.def("_test_logger", + [](const bool info, const bool debug, const bool warning) { + auto logger = Dune::XT::Common::TimedLogger().get("dune.xt.common"); + if (info) + logger.info() << "info logging works!" << std::endl; + if (debug) + logger.debug() << "debug logging works!" << std::endl; + if (warning) + logger.warn() << "warning logging works!" << std::endl; + }, + "info"_a = true, + "debug"_a = true, + "warning"_a = true); + m.def("_is_debug", []() { #ifndef NDEBUG return true; diff --git a/python/dune/xt/common/__init__.py b/python/dune/xt/common/__init__.py index 0bcf06cfe47322655bca814a1dccdab700c2ff7a..61fc9802059f5ab855023f6c9e19f1860ecd01c3 100644 --- a/python/dune/xt/common/__init__.py +++ b/python/dune/xt/common/__init__.py @@ -15,6 +15,7 @@ except ImportError: pass _init_logger_methods = list() +_test_logger_methods = list() _init_mpi_methods = list() _other_modules = ('xt.la', 'xt.grid', 'xt.functions', 'gdt') @@ -22,14 +23,15 @@ from ._common import __dict__ as module to_import = [name for name in module if not name.startswith('_')] globals().update({name: module[name] for name in to_import}) _init_logger_methods.append(module['_init_logger']) +_test_logger_methods.append(module['_test_logger']) _init_mpi_methods.append(module['_init_mpi']) DEBUG = module['_is_debug']() del to_import del module -def init_logger(max_info_level=-1, - max_debug_level=-1, +def init_logger(max_info_level=999, + max_debug_level=999, enable_warnings=True, enable_colors=True, info_color='blue', @@ -46,6 +48,18 @@ def init_logger(max_info_level=-1, for init_logger_method in init_logger_methods: init_logger_method(max_info_level, max_debug_level, enable_warnings, enable_colors, info_color, debug_color, warning_color) +def test_logger(info=True, debug=True, warning=True): + test_logger_methods = _test_logger_methods.copy() + for module_name in _other_modules: + try: + mm = import_module('dune.{}'.format(module_name)) + for test_logger_method in mm._test_logger_methods: + test_logger_methods.append(test_logger_method) + except ModuleNotFoundError: + pass + for test_logger_method in test_logger_methods: + test_logger_method(info, debug, warning) + def init_mpi(args=list()): if DEBUG: