Postpone log level detection until OC loaded#384
Postpone log level detection until OC loaded#384ChristophWurst merged 4 commits intonextcloud-libraries:masterfrom susnux:fix/initial_config
Conversation
|
Encountered this error when adding a new Vue component to core nextcloud/server#35637 and this seems to fix it! Thanks! |
| this.detectLogLevel() | ||
| } | ||
|
|
||
| return this.factory(this.context) |
There was a problem hiding this comment.
this is called regardless of the log level being read already or later after page load.
in other words, if this.context.level is changed at a later stage, it won't have an affect on the already created logger instance, will it?
There was a problem hiding this comment.
It will, as the object is not deep copied but passed by reference so the logger and the logger builder share the same context (until the site it loaded).
I pushed two additional commits providing test cases for this scenario.
(I hope this is ok, normally I would open a new PR for a new feature but I think the tests belong to this)
Sometimes the logger is loaded before the OC variable is declared, so we need to wait for OC to become available. Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
…n for NC25 Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Also added mocks for the logger itself. Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
While #383 only fixed the symptoms, this will fix the root issue that sometimes the logger is loaded before the OC variable is declared, So we need to wait for OC to become available.
Currently the behavior is nondeterministic because if the logger is loaded before the global
OCvariable was set the logger would never respect the configured logging level and stick with the default (warning even if you configured e.g. info on the back end).So you might even loose some messages.
This PR will change the behavior to a deterministic one:
Until the
OCvariable is set and the level was not set manually, the logger will no use any logging level (equivalent to debug).When the
OCvariable is set the logger will switch to that logging level.So the logger is independent to the loading order of the scripts.