Skip to content

Conversation

@susnux
Copy link
Contributor

@susnux susnux commented Nov 7, 2025

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 :)

@susnux susnux added enhancement New feature or request 3. to review labels Nov 7, 2025
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>
@susnux susnux force-pushed the feat/allow-debug-specific-app branch from 4c498bc to e79fc17 Compare November 7, 2025 11:15
@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.54%. Comparing base (64f252b) to head (e79fc17).

Files with missing lines Patch % Lines
lib/ConsoleLogger.ts 41.66% 6 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ShGKme
Copy link
Contributor

ShGKme commented Nov 7, 2025

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']
Copy link
Contributor

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?

Copy link
Contributor

@ShGKme ShGKme Nov 7, 2025

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:

  1. You see the list of the flags that can be enabled/disabled
  2. You can just toggle true/false

in contrast, with the array of strings:

  1. You need to know the strings
  2. There are no "add"/"remove" operations in the array. Only via conversion to a Set.

Copy link
Contributor

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?

Copy link
Contributor Author

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).

Copy link
Contributor

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?

Copy link
Contributor Author

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)

@susnux
Copy link
Contributor Author

susnux commented Nov 7, 2025

Maybe this is not 100% what you had in mind?
My use case is to enable debug for one app but ignore other apps.

Maybe this could be changed a bit to also allow "sub-loggers" if that is what you wanted:
Like

const scopedLogger = logger.getDebugLogger('scope')

// ...
scopedLogger.debug(...)

Where the implementation is just to pass scope to the sub-loggers context.scope state.

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'

@ShGKme
Copy link
Contributor

ShGKme commented Nov 7, 2025

Maybe this is not 100% what you had in mind?

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.

@max-nextcloud
Copy link
Contributor

max-nextcloud commented Nov 7, 2025

Thanks for looking into this @susnux .

What you are laying out in #908 (comment)
sounds like it would cover all use cases.

I'm not sure how well this would work with prefilling the data structure for autocompletion:

window.NC_LOGGER.my_app.dav = true

We could set NC_LOGGER.my_app to false as soon as a logger for the app is created. But for the scope we would need to change that to { dav: false }. This would work nicely with autocomplete until one sets NC_LOGGER.my_app to true or false. But this is really just for convenience and I don't see any way around it without making it way more complex.

@susnux
Copy link
Contributor Author

susnux commented Nov 7, 2025

this would work nicely with autocomplete until one sets NC_LOGGER.my_app to true or false.

maybe just add then a .all scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow debug logging that can be enabled / disabled

4 participants