Logging control#
Several of the different subpackages of Ubermag use logging to provide additional information if required. Each packages uses a logger with the name equal to the package name, e.g. oommfc
has a logger called oommfc
.
In Python logging information is not show by default if the level is lower than warning (see https://docs.python.org/3/howto/logging.html).
The ubermag
metapackage contains a function setup_logging
to controll logging for all its subpackages, providing two functionalities:
Control over the log level of all Ubermag packages.
Setup of a basic logging configuration to print logs to the screen.
[1]:
import ubermagutil
We can change the log level in two different ways.
We can set a default level for all packages by passing an argument to
level
(see here for available log levels).
[2]:
ubermagutil.setup_logging(level="DEBUG")
The default value is level='WARNING'
.
We have fine-grain control over per-packages levels by passing a dictionary to
package_levels
. All subpackages not specified in this dictionary use the level passed tolevel
(default'WANRING'
).
[3]:
ubermagutil.setup_logging(
package_levels={"discretisedfield": "INFO", "oommfc": "DEBUG"}
)
To show an example for this configuration, more precisely the log level 'DEBUG'
for oommfc
we can import oommfc
and ask oommfc
to find the default runner (which includes several logging messages).
[4]:
import oommfc
oommfc.runner.autoselect_runner()
2022-05-19:15:45:50,194 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:510] Starting autoselect_runner: cache_runner=True, envvar=OOMMFTCL, oommf_exe=oommf, docker_exe=docker)
2022-05-19:15:45:50,197 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:523] Step 1: Checking for the self.envvar=OOMMFTCL environment variable pointing to oommf.tcl.
2022-05-19:15:45:50,198 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:548] Step 2: is oommf_exe=oommf in PATH? Could be from conda env or manual install.
2022-05-19:15:45:50,200 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:554] Ouput from "which oommf_exe"=/opt/miniconda3/envs/ubermagdev/bin/oommf
2022-05-19:15:45:50,201 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:573] Attempt command call
2022-05-19:15:45:50,279 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:575] CompletedProcess(args=['/opt/miniconda3/envs/ubermagdev/bin/oommf', 'boxsi', '+fg', '+version', '-exitondone', '1', '-kill', 'all'], returncode=0, stdout=b'', stderr=b'<51622> OOMMF 2.0a3 info:\nOOMMF 2.0a3\n')
We can change the log level at every point of the notebook.
[5]:
ubermagutil.setup_logging(level="WARNING")
oommfc.runner.autoselect_runner()
Account lookup failure: martin
[6]:
ubermagutil.setup_logging(level="DEBUG")
oommfc.runner.autoselect_runner()
2022-05-19:15:45:51,156 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:510] Starting autoselect_runner: cache_runner=True, envvar=OOMMFTCL, oommf_exe=oommf, docker_exe=docker)
2022-05-19:15:45:51,157 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:523] Step 1: Checking for the self.envvar=OOMMFTCL environment variable pointing to oommf.tcl.
2022-05-19:15:45:51,158 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:548] Step 2: is oommf_exe=oommf in PATH? Could be from conda env or manual install.
2022-05-19:15:45:51,159 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:554] Ouput from "which oommf_exe"=/opt/miniconda3/envs/ubermagdev/bin/oommf
2022-05-19:15:45:51,159 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:573] Attempt command call
2022-05-19:15:45:51,244 oommfc:DEBUG [/home/martin/PhD/repos/ubermag-devtools/repos/oommfc/oommfc/oommf/oommf.py:autoselect_runner:575] CompletedProcess(args=['/opt/miniconda3/envs/ubermagdev/bin/oommf', 'boxsi', '+fg', '+version', '-exitondone', '1', '-kill', 'all'], returncode=0, stdout=b'', stderr=b'<51659> OOMMF 2.0a3 info:\nOOMMF 2.0a3\n')
Account lookup failure: martin