-
Notifications
You must be signed in to change notification settings - Fork 15
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 subsystem #285
Conversation
…nd leave the default at info
@@ -220,13 +228,13 @@ def report(self, print_results=True): | |||
self._population.get_population(True).index | |||
) | |||
if print_results: | |||
logger.debug("\n" + pformat(metrics)) | |||
self._logger.info("\n" + pformat(metrics)) |
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.
This potentially spits out a very large dictionary. Since these outputs are being written to output.hdf
anyway, are you sure this needs to be logged at INFO
? I think DEBUG
might still make more sense.
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.
I think this is a good point, but one to address in a different PR focused on the results system.
performance_metrics = self.get_performance_metrics() | ||
performance_metrics = performance_metrics.to_string( | ||
index=False, | ||
float_format=lambda x: f"{x:.2f}", | ||
) | ||
logger.debug("\n" + performance_metrics) | ||
self._logger.info("\n" + performance_metrics) |
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.
The same argument could be made here, but since performance metrics are much smaller, I think logging at INFO
still could make sense.
log_file = output_directory / "simulation.log" | ||
_add_logging_sink( | ||
log_file, | ||
verbosity=2, |
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.
I wish logging levels were Enums rather than ints. This would be more legible if it read verbosity=DEBUG
, but there's nothing we can do about that I guess.
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.
Will address in a separate PR
fmt += self.simulation_and_component + " - " | ||
else: | ||
fmt += self.simulation + " - " | ||
else: |
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.
Is this else supposed to be for this if
or the one above?
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.
For this if.
@@ -2,6 +2,8 @@ | |||
|
|||
import pytest | |||
import tables | |||
from _pytest.logging import LogCaptureFixture |
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.
What is _pytest
?
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.
Cargo culting. This is a pattern from the loguru docs for making pytest work correctly with loguru.
Co-authored-by: Rajan Mudambi <11376379+rmudambi@users.noreply.github.com>
Write a more extensive comment about checking for terminal logging handlers.
Add logging subsystem
Description
Category: feature
Issues: #282 and #283
The primary goal of this PR is to add a logging subsystem into vivarium and to make it have as small an impact as
possible on user facing code.
User-facing changes
add_logging_sink
,configure_logging_to_terminal
, andconfigure_logging_to_file
have been moved fromvivarium.interface.utilities
tovivarium.framework.logging.utilities
. These functions are not used invivarium_cluster_tools
but may be alive in user code (Abie pointed out he uses it in Logging in interactive settings is verbose and not configurable #283 to suppress noisy logging, but part of the goal here is to give a more sensible way to do that).{time} | {level} | {module}:{function}:{line} - {message}
. There are two new formats. The default (long) format is{time} | {level} | {simulation_name}-{component_name}:{line} - {message}
if logging from a component that has requested a named logger and{time} | {level} | {simulation_name}-{module}:{line} - {message}
if logging from a component that has requested an anonymous logger or if logging from the simulation context itself. The idea here is that the component is going to be a more intuitive (and fine-grained) logging detail than the module for researchers and straightforward to translate to modules for engineers. If that turns out not to be true, user space code can just request anonymous loggers. Additionally, there is a short format log that does{time} | {module}:{line} - {message}
that I think will be appropriate for things like running sims in parallel. Only the long format is currently exposed to users.ERROR
at the command line andDEBUG
in an interactive setting toINFO
in both settings (who thought that was a good idea originally 🙃 ).-v
logs atDEBUG
level,-q
logs atWARNING
level)logging_verbosity
argument in the initializer (2
logs atDEBUG
level,1
logs atINFO
level [default],0
logs atWARNING
level). This argument is ignored if an external tool (like the command line interface) has configured logging. External tools may want to log broader information to the same sinks and must have the ability to preempt.INFO
(formerlyDEBUG
).WARNING
(formerlyDEBUG
)INFO
(formerlyDEBUG
)concept
section of the docs.builder.logging.get_logger
and can, if desired, pass in the component name from which they want to log.Testing
CI and manual testing.