-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Dump Arrays, Objects and Exceptions to the log #12682
Conversation
Php 5.4 is now minimum requirement for oc8. You can remove this special handling. |
Unit tests are welcome |
@DeepDiver1975 - I'll add the unit tests if this extension of the logger is wanted by most and if it works with other backends |
I like this :) |
return $this->toJson($data, true); | ||
} | ||
|
||
private function toJson($data, $ignoreErrors = 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.
please kill $ignoreErrors - it is always called with true and I see no reason to do this different - THX
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.
@oparoz please kill that unused argument- THX
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.
I've moved everything into a separate class. I "just" need to add it to this PR
https://github.com/interfasys/galleryplus/blob/master/utility/normalizer.php
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.
Looks good - I'm happy to accept this class (unit tests for sure required 🙊 ) - many thanks!
yes - I'd like to see this getting part of ownCloud core - THX a lot! Please add unit tests 🙈 |
@oparoz DId you need any help? |
I just need to find the time to add the unit tests, to this PR and to many others... But if someone else wants to write them for this one, then no problem. |
@PVince81 @LukasReschke Maybe one of you have time today to do this, to review this today ;) |
moving to OC8.1 |
$count = 1; | ||
foreach ($data as $key => $value) { | ||
if ($count++ >= 1000) { | ||
$normalized['...'] = 'Over 1000 items, aborting normalization'; |
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.
Should do that in depth aswell? Also I'd stop at 100 or seomthing lower... no one looks at more entries anyway
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.
Check the Normalizer class https://github.com/interfasys/galleryplus/blob/master/utility/normalizer.php#L99
I've added a variable for that. Ideally it should come from the config, if there really is a need to play with it.
I did change it at times when looking at some objects.
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.
Well the normalizer is not in this PR
Config: 🙅 👎
You can make it a class member of this class, that's fine. But nothing more really
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.
I was thinking of adding a separate class to keep this one at a decent size, but it probably won't work because it needs to be instantiated, which means changing the ctor's sig
question instead of making this ourselves (great job btw) would it be easier/better in the long run to just add the option to use monolog instead of the oc logger. I have a working POC of that i did on one of my exploratory days. To enable it you just set 'log_type' => 'monolog' in your config. Let me know and i'll create a PR if its wanted. @DeepDiver1975 @oparoz |
@th3fallen - There have been several requests to add Monolog (#12671, #10405 which is actually yours :)), but they all have been turned down, so I decided to import and "improve" the normalizer. |
needs to be rebased |
OK, rebased, using the new Normalizer class. |
'Over ' . $maxArrayRecursion . ' items, aborting normalization'; | ||
break; | ||
} | ||
$normalized[$key] = $this->normalize($value, $depth); |
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.
depth is not increased?
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.
$depth
is only used by normalizeObject to prevent ending up with a huge log entry with details about every "sub-objects".
Arrays have their own limits.
I've tried to have sensible limits, based on my needs when investigating issues, but there might be better ways to do this.
I've run into the array's limit before for things like iConfig objects, but at the same time, it's annoying to get 50 long strings into one log entry when feeding the log with results per example.
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.
im not talking about:
[
1,
2,
...,
];
I'm talking about:
[
[
[
[
...,
],
],
],
];
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.
You're correct, array depth is not limited.
This won't work without adding |
Refer to this link for build results (access rights to CI server needed): |
Send a PR to https://github.com/owncloud/3rdparty to include the required dependency ? |
I didn't do it for 2 reasons:
So, should I just add it to 3rdparty so that people can play with the lib? |
@@ -27,6 +28,8 @@ | |||
|
|||
namespace OC; | |||
|
|||
use InterfaSys\LogNormalizer\Normalizer; |
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.
This is not defined. What does it do?
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.
It's available here and needs to be added to the list of external dependencies in 3rdparty
https://github.com/interfasys/lognormalizer
@oparoz I don't think this will make it into 8.2 -> defer to 9.0 |
Feature freeze is in 3 weeks, so I'll try to create a PR in the 3rdparty repo. I didn't have much luck getting it to work locally last time I tried. No problems in apps. I can load the lib without any issues using composer. |
2 weeks ;) https://github.com/owncloud/core/wiki/Maintenance-and-Release-Schedule#owncloud-82 |
Ah, so that paragraph on the same page needs to be updated or is this an exception?
|
This is a rough description of when something will happens. The excact dates are then determined by @cmonteroluque and announced. This is what I have written to the wiki then. So thread the exact dates as the correct ones and the text as a long term guideline. |
A new inspection was created. |
You need to switch your 3rdparty branch to this PR: owncloud-archive/3rdparty#195 Then you can dump any array, object, exception to owncloud.log, as described in the OP. @DeepDiver1975 @th3fallen @MorrisJobke @LukasReschke @PVince81 @rullzer @Xenopathic |
Superseeded by core branch PR in #19030 |
@oparoz Can I ask you to document this in the developers manual too? Thanks https://doc.owncloud.org/server/8.2/developer_manual/app/logging.html |
@MorrisJobke Added an issue in order to not forget. |
By using a 3rd party normalizer, it's possible to dump objects and arrays to the log, without having to pre-encode them.
The library used in this PR is : https://github.com/interfasys/lognormalizer
You add the variables to the context array like this:
or
Note: It has only been tested with the ownlcloud logger (log_type).