Add logging to MESA
Closed this issue · 4 comments
What's the problem this feature will solve?
Mesa's code base is expanding, and more functionality is being added all the time. This makes understanding how certain errors came about more complicated. Moreover, errors in reactive code, as used in the solara visualization, can be particullary tricky to diagnose. Having built-in logging in MESA will make diagnosing errors much easier.
Describe the solution you'd like
Add dedicated logging functionality to MESA. This entails:
- adding a logging.py that creates the root MESA logger and has some convenience functions (e.g., decorators to make logging of specific methods and functions easy and keep it out of the normal code; function for creating module loggers). See e.g., the workbench logging file for an example.
- Add a dedicated logger instance to each module. This is a recommended practice, and, given the hierarchical structure of logger names, isolating log messages becomes easy. So, you would have loggers like
mesa.model
,mesa.visualization.solara_viz
, etc. - Agree on what needs logging inside mesa and assess the performance implications. I favor debug-level logging on all methods and functions but would be curious to see what that does to model runtime.
- Agree on how to expose the logging functionality to users. For example, should we always log into a file, but where do we locate this file?
I haven't looked into python logging yet, but there is extensive official documentation, for example at
https://docs.python.org/3/howto/logging.html
I only skimmed it now, but one thing that stood out to me was the possibility to use configuration files. This might make a nice entry point for 4), exposing this to users. They might just provide their own config file to determine how and what to log (debug level, file output, etc.)
/edit removed wrong link
I haven't used configuration files before. While reading the docs, it seems that it has been superseded by DictConfig
, which allows you to use json files: See the logging cookbook.
Oops, yes, I wanted to refer to that but provided the wrong link I thought fileConfig
can load DictConfig
, but you are right, its just for the old format. The dictConfig
method loads a DictConfig
in a dictionary format and its agnostic of where that dict originated (e.g. json or yaml)