Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions python/sdist/amici/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def _setup_logger(
return log


def set_log_level(logger: logging.Logger, log_level: int | bool) -> None:
def set_log_level(
logger: logging.Logger, log_level: int | bool | None
) -> None:
if log_level is not None and log_level is not False:
if isinstance(log_level, bool):
log_level = logging.DEBUG
Expand All @@ -139,33 +141,33 @@ def get_logger(
**kwargs,
) -> logging.Logger:
"""
Returns (if extistant) or creates an AMICI logger
Returns (if exists) or creates an AMICI logger

If the AMICI base logger has already been set up, this method will
return it or any of its descendant loggers without overriding the
settings - i.e. any values supplied as kwargs will be ignored.

:param logger_name:
Get a logger for a specific namespace, typically __name__
for code outside of classes or self.__module__ inside a class
Get a logger for a specific namespace, typically ``__name__``
for code outside of classes or ``self.__module__`` inside a class

:param log_level:
Override the default or preset log level for the requested logger.
None or False uses the default or preset value. True evaluates to
logging.DEBUG. Any integer is used directly.
``None`` or ``False`` uses the default or preset value. ``True`` evaluates to
``logging.DEBUG``. Any integer is used directly.

:param console_output:
Set up a default console log handler if True (default). Only used when
Set up a default console log handler if ``True`` (default). Only used when
the AMICI logger hasn't been set up yet.

:param file_output:
Supply a filename to copy all log output to that file, or set to
False to disable (default). Only used when the AMICI logger hasn't
``False`` to disable (default). Only used when the AMICI logger hasn't
been set up yet.

:param capture_warnings:
Capture warnings from Python's warnings module if True (default).
Only used when the AMICI logger hasn't been set up yet..
Only used when the AMICI logger hasn't been set up yet.

:return:
A logging.Logger object with the requested name
Expand Down
5 changes: 5 additions & 0 deletions python/sdist/amici/sim/sundials/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
for analyzing the simulation results.
"""

import logging
import os
import warnings
from types import ModuleType
from typing import Protocol, runtime_checkable

import amici
from amici import amici_path, import_model_module
from amici.logging import get_logger

logger = get_logger(__name__, log_level=logging.DEBUG)


#: boolean indicating if this is the full package with swig interface or
# the raw package without extension
Expand Down
2 changes: 1 addition & 1 deletion python/sdist/amici/sim/sundials/_swig_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from . import ReturnDataView

logger = get_logger(__name__, log_level=logging.DEBUG)
logger = get_logger(__name__, log_level=None)


__all__ = [
Expand Down
16 changes: 16 additions & 0 deletions python/tests/test_sbml_import.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests related to amici.importers.sbml"""

import logging
import os
import re
import sys
Expand Down Expand Up @@ -229,8 +230,23 @@ def test_logging_works(observable_dependent_error_model, caplog):

rdata = run_simulation(model, solver)
assert rdata.status != AMICI_SUCCESS
# this is a DEBUG level message and should be there by default
assert "mxstep steps taken" in caplog.text

caplog.clear()

# ensure that we can control amici.sim.sundials._swig_wrappers logging
# via the public amici.sim.sundials logger
logger = logging.getLogger("amici.sim.sundials")
old_lvl = logger.level
try:
logger.setLevel(logging.WARNING)
rdata = run_simulation(model, solver)
assert rdata.status != AMICI_SUCCESS
assert "mxstep steps taken" not in caplog.text
finally:
logger.setLevel(old_lvl)


@skip_on_valgrind
def test_model_module_is_set(observable_dependent_error_model):
Expand Down
Loading