-
Notifications
You must be signed in to change notification settings - Fork 10
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
Move logging config to separate yaml, configure individual loggers #502
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #502 +/- ##
==========================================
+ Coverage 77.17% 77.19% +0.02%
==========================================
Files 66 66
Lines 8210 8209 -1
==========================================
+ Hits 6336 6337 +1
+ Misses 1874 1872 -2 ☔ View full report in Codecov by Sentry. |
45fb2c6
to
8a96af1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this makes logging easier and less polluting, so good!
Another positive thing is that I think it is good to have everything that does not affect the simulation to be separate from things that do affect the simulation. E.g. one of my goals is that ScopeSim should be able to recreate the pixels from the headers, and the logging configuration is not relevant to that.
Or to say the same thing in different words: the logging configuration is in a way configuration of an independent third party library, not a configuration of the simulator itself. So there is no 'need' to put the logging config in the same file as the simulator config, and there are benefits to keeping it separate. E.g. now we could even use some kind of 'logging-native' configuration would such a thing exist (which I don't know). Or we can switch logging frameworks without affecting our core simulator configuration. |
Agree. By this logic, we should also think about removing the |
You mean like the builtin |
Yeah, we can just use pytest for that. Never noticed that was there.
I didn't say we should actually switch the configuration, but to me it makes sense to be able to do so. |
In the long run, once we separate That would enable any other applications (think exposure time simulator) to use the library in the backend, but add its own logging configuration, which might look very different from what we're doing in ScopeSim (especially when there's a GUI involved). (Please ignore any potential exact duplicates of this comment, the Upper Friulian Subway has terrible connection and I don't know if and how often this is getting through 🙃) |
Yeah, that's what I understood 👍 |
TLDR
After thinking about this for a while and trying various things, I came to the conclusion that having the logging config in
rc.__config__
(and thus in the bottom level of all the cmds nested chainmap thingies) is indeed such a deceased hoofed creature. Thus, to cut losses now and avoid any sunken cost fallacy, I decided to remove the logging stuff from there and put it into a separate placerc.__logging_config__
, and a new, separate yaml.But why?
Problems with logging in the chainmap
NestedMapping
didn't fully support keys containing a.
character in the string, because it created an ambiguity when using dot-separated "bang keys". See below why this can't be properly fixed.Why do we even need dots in keys?
Loggers follow a hierarchical namespace structure equivalent to Python's package.module.whatever namespace, separated by dots. To be able to configure individual loggers by default in the dict config (which is the cleanest method of initially configuring logging), we need to be able to include keys containing dots in this nested dict.
Rejected alternative
I tried for a bit to enable keys containing dots for the
NestedMapping
class. In the end, I was able to make it work, but really only for retrieving existing keys. Adding a new key (or, to a lesser extent, modifying an existing one) created an ambiguity. Consider the following case: ANestedMapping
instance contains a top-level key"XYZ"
, which leads to a sub-dict with the key"ab.cd"
that in turn leads to a dict containing the key"m"
. Retrieving"!XYZ.ab.cd.m"
can in theory (and indeed in practice, I did that) be implemented to look up the entire thing in a tree-like manner until the correct key is found. If a new item is to be set with the key"!XYZ.ab.cd.k"
, how is theNestedMapping
supposed to know if that's meant to be a key"k"
in the sub-dict"ab.cd"
, or in"cd"
, which is in turn a sub-dict of"ab"
(and that itself of"XYZ"
)?So, instead of implementing a hacky way to include these things and have potential ambiguities in there, I think it's preferable to simply accept it as a limitation of
NestedMapping
that keys cannot contain dots. As outlined above, this might have actually several benefits in the context of the logging config, in keeping it in a separate place.