Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging to MESA #2461

Closed
quaquel opened this issue Nov 6, 2024 · 4 comments
Closed

Add logging to MESA #2461

quaquel opened this issue Nov 6, 2024 · 4 comments

Comments

@quaquel
Copy link
Member

quaquel commented Nov 6, 2024

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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?
@Corvince
Copy link
Contributor

Corvince commented Nov 12, 2024

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

@quaquel
Copy link
Member Author

quaquel commented Nov 12, 2024

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.

@Corvince
Copy link
Contributor

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)

@quaquel
Copy link
Member Author

quaquel commented Nov 25, 2024

with #2506 merged, this is now addressed.

@quaquel quaquel closed this as completed Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants