-
Notifications
You must be signed in to change notification settings - Fork 3
feat: allow runtime debugging specific app(s) #908
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
base: main
Are you sure you want to change the base?
Conversation
Allows setting a window global variable (`__NC_LOGGER_DEBUG__`) to an array of app ids for which the logger will enforce the debug logging level. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
4c498bc to
e79fc17
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #908 +/- ##
==========================================
- Coverage 98.46% 90.54% -7.93%
==========================================
Files 4 5 +1
Lines 65 74 +9
Branches 13 16 +3
==========================================
+ Hits 64 67 +3
- Misses 0 6 +6
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Could you show what Max's or mine code example in that issue would look like with this implementation? |
| // debug a single app | ||
| window.__NC_LOGGER_DEBUG__=['YOUR_APP_ID'] | ||
| // debug multiple apps | ||
| window.__NC_LOGGER_DEBUG__=['files', 'viewer'] |
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.
Does it mean there is no feature support like in the linked issue, but only per-app support?
So if you want to have a debug flag for a specific feature, you need to call it another app, correct?
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.
In the issue the proposal was to have an object with boolean flags. It's quite convenient because:
- You see the list of the flags that can be enabled/disabled
- You can just toggle true/false
in contrast, with the array of strings:
- You need to know the strings
- There are no "add"/"remove" operations in the array. Only via conversion to a Set.
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.
Also, why make it a __BUILD_TIME_CONST__ or _private_variable_ like and not a public?
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.
Basically the idea is not to break existing loggers and need for refactoring your code base.
But instead allow to selectively enable debug logging for specific apps instead of all apps that would flood the logs.
Also, why make it a BUILD_TIME_CONST or private_variable like and not a public?
Reduce risks here to break anything as this is a global variable.
Alternative would be to move to OCA but then only OCA.Core would be kind of safe, as other name spaces could be used by an app (e.g. proposed OCA.Logger could be used by an app called logger).
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.
Basically the idea is not to break existing loggers and need for refactoring your code base.
Was @max-nextcloud proposal breaking?
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.
Like you have to create a new logger that what I meant (as described below I might have a different use case)
|
Maybe this is not 100% what you had in mind? Maybe this could be changed a bit to also allow "sub-loggers" if that is what you wanted: const scopedLogger = logger.getDebugLogger('scope')
// ...
scopedLogger.debug(...)Where the implementation is just to pass So that the usage would be (imagine global log level is warn): logger.debug('debug foo')
scopedLogger.debug('bar')
// output: *no output because global state is only warning*
window.NC_LOGGER.app.scope = true
logger.debug('debug foo')
scopedLogger.debug('bar')
// output: 'debug foo'
// But also debug for all log messages of that app:
window.NC_LOGGER.app = true
logger.debug('debug foo')
scopedLogger.debug('bar')
// output: 'debug foo' 'bar'Here the nice thing is this could also work without having to create many loggers per feature, but just pass context directly: window.NC_LOGGER.my_app.dav = true
logger.debug('scoped', { scope: 'dav' })
logger.debug('non scoped')
// output: 'scoped'
|
The issue is about having an optional feature-specified debug logger, allowing your apps to have heavily logged features that can be optionally enabled. That is also the same we would like to have in Talk, for example, because we need not "entire Talk" logging to be disabled, but specific parts. Same as Office apps, we have heavily used networking, for example. |
|
Thanks for looking into this @susnux . What you are laying out in #908 (comment) I'm not sure how well this would work with prefilling the data structure for autocompletion: window.NC_LOGGER.my_app.dav = trueWe could set |
maybe just add then a |
This allows setting a window global variable (
__NC_LOGGER_DEBUG__)to an array of app ids for which the logger will enforce the debug logging level.
#894 convinced me that this is really handy, I personally have also two use cases for this as debugging will be a lot easier then :)