Wired mongo's logs to an injected ILogger #114
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #113
Fixes #94
Fixes #95
This PR would allow solving #94 and #95 with the following call, although disabling logs is not the direct purpose of this PR:
How it works
When starting the mongod process, the
ProcessControl
evaluates if anILogger
has been injected or if it'snull
. Ifnull
, then MongoRunner works as usual, by wiring the logs to .NET's console and debug outputs. Otherwise, it parses mongo's logs and wires them to theILogger
.Parsing mongo's logs is a discussable choice. I'm open for discussing this choice. I mainly needed to parse the json logs to get the
severity
so that we would callILogger
with the appropriate level.Risks and Impacts
Microsoft.Extensions.Logging.Abstractions
for theILogger
interface, andSystem.Text.Json
to parse the mongo logs.id
property to be astring
, whereas it is actually anint
.string windowTitle
from theProcessControl.StartAndWait()
methods, as I noticed they were unused. However, the class and the methods are public, meaning it could break usage if anyone has been using these methods. I believe the classProcessControl
should remaininternal
. Is that correct? Do we risk breaking anyone's usage with the changes I made here?Performance
I ran this modified version of Mongo2Go on a test suite of 296 passing tests. I have not noticed any significant impact or improvement on execution time of the test suite. Duration kept between 02:00 and 2:20 (parallel), or 20-25 minutes cumulative. No significant change either caused by the logging level or the logging target.