bio_rtd.logger¶
Module with different loggers for rtd models and its components.
RtdLogger is main abstract class that all other loggers implement. Loggers handle non-fatal events (info, debug, warning and non-fatal error messages) as well as internally stored intermediate process data.
General guidelines:
Skip logging and raise Exception directly in case of a serious error.
ERROR messages for highly probable sources of inaccuracies within the model (e.g. in case a probability distributions contains only a few data points), but we don’t necessarily want to raise an exception.
WARNING messages for warnings about potential sources of inaccuracy in the model.
INFO for storing short intermediate data (everything apart from time series).
DEBUG for storing long intermediate data (time series).
See also
Examples
>>> log = DefaultLogger()
>>> log.e("Error Description") # log error
Traceback (most recent call last):
RuntimeError: Error Description
>>> log.w("Warning Description") # log waring
Warning Description
>>> log.i("Info") # log info
>>> log.log_data = True
>>> log.log_level_data = RtdLogger.DEBUG
>>> data_tree = dict()
>>> log.set_data_tree("test_data_tree", data_tree)
>>> log.i_data(data_tree, "a", 3) # store value in logger
>>> log.d_data(data_tree, "b", "lots_of_data") # store at DEBUG level
>>> log.get_data_tree("test_data_tree",)["b"]
'lots_of_data'
>>> log = StrictLogger() # raises RuntimeError already on WARNING level
>>> log.w("Warning Info")
Traceback (most recent call last):
RuntimeError: Warning Info
DefaultLogger¶
-
class
bio_rtd.logger.
DefaultLogger
(log_level=30, log_data=False, log_level_data=10)[source]¶ Bases:
bio_rtd.logger.RtdLogger
Prints warnings to terminal and raises errors.
Does not store data.
- Parameters
log_level (
int
) – Default: WARNING.log_data (
bool
) – Default: False.log_level_data (
int
) – Default: DEBUG.
Examples
>>> log = DefaultLogger() >>> data_tree = dict() >>> log.set_data_tree("my_uo", data_tree) >>> log.i_data(data_tree, "par_i", 8.4) # ignored >>> log.d_data(data_tree, "par_d", 5.4) # ignored >>> len(data_tree.keys()) # no data 0 >>> log.i(msg="Info msg") # ignored >>> log.w(msg="Warning msg") Warning msg >>> log.e(msg="Error msg") Traceback (most recent call last): RuntimeError: Error msg
See also
DataStoringLogger¶
-
class
bio_rtd.logger.
DataStoringLogger
(log_level=30, log_data=True, log_level_data=10)[source]¶ Bases:
bio_rtd.logger.RtdLogger
Prints messages to terminal. Stores all data.
- Parameters
log_level (
int
) – Default: WARNING.log_data (
bool
) – Default: True.log_level_data (
int
) – Default: DEBUG.
Examples
>>> log = DataStoringLogger() >>> data_tree = dict() >>> log.set_data_tree("my_uo", data_tree) >>> log.i_data(data_tree, "par_i", 8.4) # stored >>> log.d_data(data_tree, "par_d", 5.4) # stored >>> len(data_tree.keys()) # no data 2 >>> data_tree["par_i"] 8.4 >>> data_tree["par_d"] 5.4 >>> log.i(msg="Info msg") # ignored >>> log.w(msg="Warning msg") Warning msg >>> log.e(msg="Error msg") Error msg >>> log.log_level = log.INFO >>> log.i_data(data_tree, "par_i_2", 18.4) # stored and printed Value set: par_i_2: 18.4 >>> data_tree["par_i_2"] 18.4
See also
StrictLogger¶
-
class
bio_rtd.logger.
StrictLogger
[source]¶ Bases:
bio_rtd.logger.RtdLogger
Raises RuntimeError on warning and error messages.
log_level = WARNING.
log_data = False.
Examples
>>> log = StrictLogger() >>> log.i(msg="Info msg") # ignored >>> log.w(msg="Warning msg") Traceback (most recent call last): RuntimeError: Warning msg >>> log.e(msg="Error msg") Traceback (most recent call last): RuntimeError: Error msg
See also
RtdLogger¶
-
class
bio_rtd.logger.
RtdLogger
(log_level=30, log_data=False, log_level_data=10)[source]¶ Bases:
abc.ABC
Abstract class for log and log data in rtd models.
Logger has different levels: DEBUG, INFO, WARNING, ERROR. Logger has option to hold copies of intermediate data.
- Variables
log_level – Verbosity level for messages. Default = WARNING.
log_data – If True, logger collects copies of intermediate data. Default = False.
log_level_data – ‘Verbosity level’ for data. Default = DEBUG. Ignored if log_data is False.
-
ERROR
= 40¶ Log level ERROR.
ERROR level is meant for signaling events (with messages) that very likely impact the accuracy of the model.
-
WARNING
= 30¶ Log level WARNING.
WARNING level is meant for signaling events (with messages) that might be the source of inaccuracies in the model.
-
INFO
= 20¶ Log level INFO.
INFO level is meant for events that might indicate potential mishaps in the model, but can also occur normally (e.g. if surge tank runs dry). This info might help explain the spectra, but it might also be a normal occurrence during the shut-down phase.
INFO level is also meant for keeping small intermediate results (no time series) in logger.
-
DEBUG
= 10¶ Log level DEBUG.
DEBUG level is meant for keeping also large intermediate data (time series) in logger.
-
i
(msg)[source]¶ Log message at INFO level
INFO level is meant for events that might indicate potential mishaps the model, but can also occur normally.
Examples
- Reporting that surge tank ran dry.
This info might help explain the spectra, but it might just as well be a normal occurrence during the shut-down phase.
-
w
(msg)[source]¶ Log message at WARNING level
WARNING level is meant for signaling events that might be the source of inaccuracies in the model.
Examples
Suspicious probability distributions. Empty concentration of flow rate profiles. Assumptions that might impact the results, such as assumptions during steady-state estimation.
-
e
(msg)[source]¶ Log message at ERROR level
ERROR level is meant for signaling events that are very likely the source of or the sign of inaccuracies in the model, but not severe enough to raise an exception in all situations (e.g. in an interactive session via GUI).
If the issue is big enough to warrant an exception, then raise the exception instead of using this log.
Examples
Probability distribution with only few data points. Probability distribution with a high cut-off at time 0. Load phase of PCC being shorter than the rest of the process.
-
set_data_tree
(data_tree_id, data_tree)[source]¶ Seeds data tree in root dictionary.
Typically tree_id = uo.id and tree_root = dict().
Unit operation needs to save a reference to the tree_root in order to store data in this logger.
- Parameters
data_tree_id (str) – Id of root tree (typically id of unit operation).
data_tree (dict) – Root for data logging (for that unit operation).
Examples
>>> log = DataStoringLogger() >>> data_tree = dict() >>> log.set_data_tree("my_uo", data_tree) >>> log.i_data(data_tree, "par_a", 10.4) >>> data_tree["par_a"] 10.4
-
set_branch
(data_tree, branch_name, branch)[source]¶ Seeds branch into data tree.
Typically used to store data from nested unit operations or parts of unit operations (evaluation data of probability distributions, breakthrough profiles, etc.).
- Parameters
data_tree (dict) – Parent data tree.
branch_name (dict) – Branch (child tree) name.
branch (dict) – Branch (child tree).
Examples
>>> log = DataStoringLogger() >>> data_tree = dict() >>> branch_tree = dict() >>> log.set_data_tree("my_uo", data_tree) >>> log.set_branch(data_tree, "pdf", branch_tree) >>> log.i_data(branch_tree, "par_b", 8.4) >>> data_tree["pdf"]["par_b"] 8.4 >>> branch_tree["par_b"] 8.4
-
i_data
(tree, key, value)[source]¶ Log smaller data (no time series).
Populates (key, value.copy()) pair into tree if log_level_data >= INFO and log_data is True.
If the copy of the value is stored, then the self._on_data_stored function is called.
-
d_data
(tree, key, value)[source]¶ Log larger intermediate data (time series).
Populates (key, value.copy()) pair into tree if log_level_data >= DEBUG and log_data is True.
If the copy of the value is stored, then the self._on_data_stored function is called.