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
feat(core): allow overriding global logging options on per-query basis #4273
Conversation
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.
that was fast! i just added a comment how this could work to the issue
btw i am rebasing the v6 branch now, so you might wanna recreate the PR once i am done |
@B4nan sounds good; just don't update this branch and I'll just reset everything and force pull when it's ready Also I just realized failures kinda make this weird... should Edit: How about this? isEnabled(namespace: LoggerNamespace, context?: LogContext) {
if (context?.isDisabled !== undefined && context.isDisabled !== false) {
if (context.isDisabled === true) {
// Disable for ALL
return false;
} else if (context.isDisabled === 'on-success'
&& context.level
&& !['warning', 'error'].includes(context.level)) {
// Disable only on success and the level was NOT an error state
return false;
}
}
return !!this.debugMode && (!Array.isArray(this.debugMode) || this.debugMode.includes(namespace));
} |
236251c
to
99b4271
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## v6 #4273 +/- ##
==========================================
+ Coverage 99.43% 99.67% +0.24%
==========================================
Files 219 219
Lines 14457 14504 +47
Branches 3314 3324 +10
==========================================
+ Hits 14375 14457 +82
+ Misses 81 46 -35
Partials 1 1
☔ View full report in Codecov by Sentry. |
I don't think we want to print failed queries when global logging is disabled, but for the local override it could be a good thing. I care more about the API in FindOptions, and there I would like the edit: looking at the implementation, I guess it could be just |
I'd be game to replace Re: |
the whole point of this feature is to override the global value - so its irrelevant what the default is and yes, i was thinking about a dedicated option in |
What a painful rebase, made two super small mistakes and it has cost me an additional hour of debugging 🤦 But it should be ready now. |
@B4nan oof, sorry man... well it should be trivial for me to fix the branch and re-push. I'll do it first thing tomorrow and read through the comments from this evening that I missed. |
99b4271
to
34b468e
Compare
} else if (context.isDisabled === 'on-success' | ||
&& context.level | ||
&& !['warning', 'error'].includes(context.level)) { | ||
// Disable only on success and the level was NOT an error state | ||
return false; | ||
} |
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.
one code style thing + no need for else if
when you return
} else if (context.isDisabled === 'on-success' | |
&& context.level | |
&& !['warning', 'error'].includes(context.level)) { | |
// Disable only on success and the level was NOT an error state | |
return false; | |
} | |
} | |
if ( | |
context.isDisabled === 'on-success' && | |
context.level && | |
!['warning', 'error'].includes(context.level) | |
) { | |
// Disable only on success and the level was NOT an error state | |
return false; | |
} |
btw i am not completely sold on the idea of the on-success
value. if a query fails, it will result in error which has the query inside the error message already, i think we dont need to enforce it here when logging is disabled. try it in a real app to see, iirc it works this way.
that's also the reason why i was asking for some integration tests, to see how it will actually work for users
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.
Oh sorry, I didn't think you'd re-review after I resolved the merge stuff... I had some of that stuff locally but just wanted to fix the branch after the rebase. here's what I'm planning:
enabled
will act as a master override; if disabled
no logs will be output. Period.
If debugMode
is set, it'll be used instead of what the logger was initialized with as a local override.
Sound good?
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.
Soooooooo I started to update the docs and realized the debugMode
flag really doesn't make sense because right now only .find
and .findOne
support the new options. Should we remove that until we're able to add it to the other entity manager methods?
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 me this is about the find methods mainly, i'd keep it, you need to be able to set what to log (query or query + query params), right?
i guess the flush method should support this too somehow
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.
Just pushed the changes; let me know what you'd like to do. My recommendation is to pull the debugMode
for now and add it back later when it's actually relevant
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.
Yea eventually I'd love for this to be added to update
, flush
, and persistAndFlush
... that was something I hoped to work on next. If you're good with it as is, I can update the docs just not totally sure how 😬
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.
Before v6 branch gets merged to master, those docs are not deployed anywhere, so we can have something in progress there, not a huge deal.
I'd like to merge it within a few weeks, let's say around half of may.
@B4nan this is ready to go unless you want an integration test; happy to write one, just can't figure out where they live (aside from the issue tests) |
They live everywhere :] I'd say more than 90% of the tests are integration tests. I usually use the |
Is there a feature you think most closely relates to this? Should I just use the logger.test.ts file? Do you have a good example of a simple integration test I could use as a baseline? |
All (or most of) the issue tests are integration test examples - they init the ORM and use the EM API. I would create a new folder I'd like to see a test that has |
@B4nan I made an integration test but it isn't working as expected... can you take a look and tell me why you think it isn't working? I added that console in there to help with testing; if I set |
Why didn't you just copy the approach with the existing I think your problem is that you only adjust the Or maybe its not problem with the test, but the implementation, I can take a closer look later this week if you want. |
@B4nan great catches, sorry for the sloppiness on those 😬 should be ready again |
docs/docs/logging.md
Outdated
@@ -86,7 +86,7 @@ const author = await em.findOne(Author, { id: 1 }, { loggerContext: { label: 'Au | |||
|
|||
### Changing `debugMode` or disabling logging for specific queries | |||
|
|||
If you'd like to disable queries on a per-query basis, you can leverage the `isDisabled` flag within `FindOptions`: | |||
If you'd like to disable logging on a per-query basis, you can leverage the `enabled` flag within `FindOptions`: |
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 flag is logging.enabled
, this still sounds a bit like it should be FindOptions.enabled
otherwise it looks good
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.
How about the new version?
Changing
debugMode
or disabling logging for specific queriesIf you'd like to disable logging or change the debug mode on a per-query basis, you can leverage
FindOptions.logging
and itsenabled
ordebugMode
property:Closes #4223