optapy / optapy

OptaPy is an AI constraint solver for Python to optimize planning and scheduling problems.
https://www.optapy.org/
Apache License 2.0
277 stars 21 forks source link

JSON logging #149

Open mmmvvvppp opened 1 year ago

mmmvvvppp commented 1 year ago

Is there any way to make OptaPy log with a JSON format? It seems the handler in the optaplanner_python_logger is disabled, otherwise I'd be trying to provide a custom handler, e.g. https://pypi.org/project/python-json-logger/

Christopher-Chianelli commented 1 year ago

This is complicated, since we don't actually use a Python logger, but a Java logger which our Python logger acts as a wrapper for:

https://github.com/optapy/optapy/blob/3c35ef7600e327586e69e459e60894c22be7bf5e/optapy-core/src/main/python/optaplanner_python_logger.py#L6-L37

Having the Java logger call the Python logger on the solve thread will probably massively decrease performance, due to FFI calls being so costly and Python having an interpreter lock. Since solving mostly happen in Java (since constraints are translated to Java with jpyinterpreter), having the Java logger call the Python logger in a separate thread should not be as costly, but I would need to write a custom appender for logback/slf4j.