-
Notifications
You must be signed in to change notification settings - Fork 879
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 #2506
base: main
Are you sure you want to change the base?
Add logging to MESA #2506
Conversation
Performance benchmarks:
|
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Honestly, I have very minimal knowledge about python logging best practices and not the time currently to investigate in it. Thus, I don't feel qualified to do a code review of this PR. But I still would like to have this included! I don't know how other maintainers feel about this, but since this PR is strictly add-on and should not break any existing features and you have a proven track-record of excellent code quality I am fine with approving this PR anytime you think its ready @quaquel. If there is some specific code you want me/someone else to look at, just say so. The only question I have right now is that mesa_logging seems to do some basic generic stuff not related to mesa at all. While its great to have full control, its also something we need to maintain. Aren't there some logging libraries for these kind of things? |
Thanks!
This is a good question. I have allways just used the logging library that ships with stdlib, but never bothered to look at other solutions. The built-in logging library has been part of Python since 2002, and its API has not really changed (as reflected by its camelcase notation). It was heavily modeled on log4j and There are various good overview pages of logging libraries. This one, for example, is quite recent and covers some interesting libraries. My impression, based on this and other posts, is that everyone acknowledges the importance and value of the built-in logging library. It is feature-complete but requires some boilerplate code (as you point out) and lacks modern logging features. You can add these yourself, and there are add-on libraries that add features (e.g., for structured logging using JSON). Another popular option is logoru. Based on the docs and playing with it a bit, it offers a more modern and Pythonic API as well as nice features like pretty printing and built-in support for logging from multiple processes (relevant for batchrunning). Another notable library in beta is picologging. This is a drop-in replacement for stdlib logging, developed by Microsoft with the aim of being an order of magnitude faster. The fact that Microsoft chooses to abide by the API of the built-in logging library speaks to the status of the built-in logging library. I am currently inclined to stick with the built-in logging functionality. This avoids adding new dependencies. The API is rock-solid and has not changed since Python 2.3 or so. So, maintenance on our end will largely be a non-issue once our boilerplate code is final and covered by tests. We can even play with pico logging if we think we need the speed-up. Moreover, I am quite familiar with this library already. However, if there are features that you or any of the other maintainers would like to have in the logging that are well served by loguru, I am happy to take a closer look at that instead. |
This is WIP, but showcases how we can add logging to MESA. It adds a new logger module with a couple of helper functions, and two decorators (one for adding logging to functions, an another for adding logging to methods).
Its use is illustrated in
solara_viz
andmodel
, and the boltzman wealth example shows it use. It is WIP.Current log output in stderr:
feedback welcome.
I will add