Skip to content
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

Conditional logging #15965

Merged
merged 2 commits into from
May 19, 2015
Merged

Conditional logging #15965

merged 2 commits into from
May 19, 2015

Conversation

MorrisJobke
Copy link
Contributor

Log condition for log level increase based on conditions. Once one of these conditions is met, the required log level is set to debug. This allows to debug specific requests, users or apps

Supported conditions (setting log_condition in config.php):
- secret: if a request parameter with the name log_secret is set to this value the condition is met
- users: if the current request is done by one of the specified users, this condition is met
- apps: if the log message is invoked by one of the specified apps, this condition is met

This would be really helpful to debug bigger installations where enabling a higher log level isn't a option because of the huge amount of log messages. cc @felixboehm @butonic

cc @nickvergessen @PVince81 @rullzer @Xenopathic @Raydiation @DeepDiver1975

@MorrisJobke
Copy link
Contributor Author

@MorrisJobke
Copy link
Contributor Author

I used the internal \OC\SystemConfig here to not run into cyclic conditions here. As this is the logger I want to reduce the needed bootstrapped system to a minimum. Otherwise it could be possible to no able to log, because the injected object couldn't be build. The system config was also required previously. And as this is an internal class I think this is not a problem. Opinions?

@felixboehm
Copy link
Contributor

Awesome stuff, logfiles often are so big and this really helps

@karlitschek
Copy link
Contributor

nice idea 👍

@DeepDiver1975
Copy link
Member

rebased after merge of #15958

@DeepDiver1975
Copy link
Member

@MorrisJobke unit tests are broken

Test\Logger::testInterpolation
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => '1 {Message {nothing} Bob Bar a}'
 )

/var/jenkins/workspace/pull-request-analyser-ng-simple@3/label/SLAVE/tests/lib/logger.php:32

@MorrisJobke
Copy link
Contributor Author

I added a unit test for the app condition.

@MorrisJobke
Copy link
Contributor Author

@LukasReschke @nickvergessen @rullzer @Xenopathic Do you want to review?

@LukasReschke
Copy link
Member

"want"

* debug specific requests, users or apps
*
* Supported conditions:
* - ``secret``: if a request parameter with the name `log_secret` is set to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared_secret?

* remove duplicate code from child classes
@MorrisJobke
Copy link
Contributor Author

Do we want to use a header or not?

@MorrisJobke
Copy link
Contributor Author

BTW: all the other comments are addressed.

* Defaults to an empty array.
*/
'log.condition' => [
'secret' => '57b58edb6637fe3059b3595cf9c41b9',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Erm? 🙈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now doc and content is not the same anymore 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ... forgot that one

 * Log condition for log level increase based on conditions. Once one of these
   conditions is met, the required log level is set to debug. This allows to
   debug specific requests, users or apps

 * Supported conditions (setting `log_condition` in `config.php`):
    - `shared_secret`: if a request parameter with the name `log_secret` is set to
                this value the condition is met
    - `users`:  if the current request is done by one of the specified users,
                this condition is met
    - `apps`:   if the log message is invoked by one of the specified apps,
                this condition is met
 * fix unit test and add app log condition test
@scrutinizer-notifier
Copy link

A new inspection was created.

@ghost
Copy link

ghost commented May 18, 2015

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/12374/
🚀 Test PASSed.🚀
chuck

@MorrisJobke
Copy link
Contributor Author

@LukasReschke @nickvergessen @rullzer @Xenopathic Ready for review :)

@rullzer
Copy link
Contributor

rullzer commented May 19, 2015

Working very nice!
I would like to see a header as well (maybe different PR, if it is to much work since this should get in). So debugging the OCS API etc becomes a bit easier.

As mentioned on IRC the call_user_func stuff makes me cry. But also that should be addressed in another PR.

👍 !

@@ -39,10 +39,7 @@ public static function init() {
* @param int $level
*/
public static function write($app, $message, $level) {
$minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
if ($level >= $minLevel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed? @MorrisJobke THX

@DeepDiver1975
Copy link
Member

👍

DeepDiver1975 added a commit that referenced this pull request May 19, 2015
@DeepDiver1975 DeepDiver1975 merged commit a52afb0 into master May 19, 2015
@DeepDiver1975 DeepDiver1975 deleted the conditional-logging branch May 19, 2015 10:00
mmattel pushed a commit to mmattel/core that referenced this pull request May 22, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Aug 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants