Open jonrkarr opened 3 years ago
The log file is much better. Preferably, there would be a log object rather than logging to a file and then parsing that log file.
However, the log file doesn't work for me.
The file logging example at https://sys-bio.github.io/libOmexMeta/docs-build/errors_and_logging/errors_and_logging.html doesn't work for me. The console logger works, but not the file logger.
I used the example exactly, with logger_file = "log.log"
and with the CellML edited to be invalid so it should find an error.
# switching to the file logger
from os.path import join, exists, dirname, abspath
from os import remove
from pyomexmeta import RDF, Logger
cellml = '''<?xml version=\"1.1\" encoding=\"UTF-8\"?>
<model xmlns=\"http://www.cellml.org/cellml/1.1#\" xmlns:cmeta=\"http://www.cellml.org/metadata/1.0#\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:bqs=\"http://www.cellml.org/bqs/1.0#\" xmlns:semsim=\"http://bime.uw.edu/semsim/#\" xmlns:dc=\"http://purl.org/dc/terms/\" xmlns:vCard=\"http://www.w3.org/2001/vcard-rdf/3.0#\" name=\"annotation_examples\" cmeta:id=\"annExamples\">
<component name=\"main\">
<variable cmeta:id=\"main.Volume\" initial_value=\"100\" name=\"Volume\" units=\"dimensionless\" />
<variable cmeta:id=\"main.MembraneVoltage\" initial_value=\"-80\" name=\"MembraneVoltage\" units=\"dimensionless\" />
<variable cmeta:id=\"main.ReactionRate\" initial_value=\"1\" name=\"ReactionRate\" units=\"dimensionless\" />
</component>
</model'''
logger_file = "log.log"
print("check logger_file: " , logger_file)
# if already exists, remove
if exists(logger_file):
remove(logger_file)
assert not exists(logger_file)
# activate the file logger
Logger.file_logger(logger_file)
rdf = RDF.from_string(cellml, syntax="turtle") # nothing is emitted to console
# now check logger_file
with open(logger_file, 'r') as file:
print(file.read())
Version: 1.2.12 Python: 3.9.5 OS: Ubuntu
I think it would also be helpful to have a error attribute somewhere so that users can at least detect whether there's an error without having to use the file logger.
Right now, I think any user would have to use the file logger unless they were confident that all RDF and all model XML were valid. Then they'd have to read and parse the logs to determine whether there were errors.
There is get_last_error
Python end, C end but it is currently not being used that much.
It'd be more precise if we could use a code example to illustrate what kind of API you're after - it doesn't matter if the support doesn't exist yet. Also, remember that throwing/raising the errors that come through from reading or serializing is hard since they are logged by the redland libraries. I'm not sure (off the top of my head) how I would convert the C Redland library logging messages into Python or even c++ errors that can be thrown/raised instead of logged.
An API that makes it easy to get a list of issues, the level of each issue, and the message associated with each issue would be helpful. This would avoid the need to setup a log file and then parse the log file for errors. I don't have a strong opinion about exactly what this needs to look like.
Methods such as these would be fine:
Here's one example from libCellML: https://libcellml.org/documentation/api/v0.2.0/classlibcellml_1_1Logger. Another is libSBML: http://sbml.org/Software/libSBML/5.18.0/docs/python-api/classlibsbml_1_1_s_b_m_l_error_log.html.
Does 28528c8637969b77738dbe93f42c92c4d90833e3 with the new logging interface resolve this problem? (aka release v.1.2.12?)