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

Dump Arrays, Objects and Exceptions to the log #12682

Closed
wants to merge 1 commit into from
Closed

Dump Arrays, Objects and Exceptions to the log #12682

wants to merge 1 commit into from

Conversation

oparoz
Copy link
Contributor

@oparoz oparoz commented Dec 8, 2014

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:

$this->logger->debug("Here is what's inside this FileInfo object: {fileinfo}", array(
    'app' => 'myApp',
    'fileinfo' => $fileInfo,
));

or

try {
    throw new \Exception("I want to be logged as an Exception!");
} catch (\Exception $e) {
    $this->logger->debug("I'm logging the full Exception object here: {exception}", array(
        'app' => 'myApp',
        'exception' => $e,
    ));
}

Note: It has only been tested with the ownlcloud logger (log_type).

@oparoz oparoz mentioned this pull request Dec 8, 2014
@DeepDiver1975
Copy link
Member

Php 5.4 is now minimum requirement for oc8. You can remove this special handling.

@DeepDiver1975
Copy link
Member

Unit tests are welcome

@oparoz
Copy link
Contributor Author

oparoz commented Dec 8, 2014

@DeepDiver1975 - I'll add the unit tests if this extension of the logger is wanted by most and if it works with other backends

@MorrisJobke
Copy link
Contributor

I like this :)

return $this->toJson($data, true);
}

private function toJson($data, $ignoreErrors = false) {
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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!

@DeepDiver1975
Copy link
Member

@DeepDiver1975 - I'll add the unit tests if this extension of the logger is wanted by most and if it works with other backends

yes - I'd like to see this getting part of ownCloud core - THX a lot! Please add unit tests 🙈

@MorrisJobke MorrisJobke added this to the 8.0-current milestone Dec 9, 2014
@MorrisJobke
Copy link
Contributor

@oparoz DId you need any help?

@oparoz
Copy link
Contributor Author

oparoz commented Dec 19, 2014

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.

@MorrisJobke
Copy link
Contributor

@PVince81 @LukasReschke Maybe one of you have time today to do this, to review this today ;)

@DeepDiver1975
Copy link
Member

moving to OC8.1

@DeepDiver1975 DeepDiver1975 modified the milestones: 8.1-next, 8.0-current Dec 22, 2014
$count = 1;
foreach ($data as $key => $value) {
if ($count++ >= 1000) {
$normalized['...'] = 'Over 1000 items, aborting normalization';
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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

@DeepDiver1975 DeepDiver1975 modified the milestones: 8.2-next, 8.1-current Apr 2, 2015
@th3fallen
Copy link
Contributor

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

@oparoz
Copy link
Contributor Author

oparoz commented Apr 11, 2015

@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.
I don't think it would require much effort to maintain that class since I don't expect the number of variable types in PHP to change frantically over the years.

@nickvergessen
Copy link
Contributor

needs to be rebased

@oparoz
Copy link
Contributor Author

oparoz commented Apr 13, 2015

OK, rebased, using the new Normalizer class.
Let me know what needs to be adjusted or if it breaks anything.

@oparoz oparoz self-assigned this Apr 13, 2015
'Over ' . $maxArrayRecursion . ' items, aborting normalization';
break;
}
$normalized[$key] = $this->normalize($value, $depth);
Copy link
Contributor

Choose a reason for hiding this comment

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

depth is not increased?

Copy link
Contributor Author

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.

Copy link
Contributor

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:

[
    [
        [
            [
                ...,
            ],
        ],
    ],
];

Copy link
Contributor Author

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.

@oparoz
Copy link
Contributor Author

oparoz commented Apr 27, 2015

This won't work without adding interfasys/lognormalizer to the list of 3rd party dependencies, so all tests will fail until that happens.

@ghost
Copy link

ghost commented Apr 30, 2015

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

nooo432

@PVince81
Copy link
Contributor

PVince81 commented Jul 3, 2015

Send a PR to https://github.com/owncloud/3rdparty to include the required dependency ?

@oparoz
Copy link
Contributor Author

oparoz commented Jul 3, 2015

I didn't do it for 2 reasons:

  1. There is an ongoing discussion about moving away from using that 3rdparty folder
  2. Adding the dependency makes it permanent, until removed if this PR is rejected and so I was wondering what the process was to sync PRs

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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

@MorrisJobke
Copy link
Contributor

@oparoz I don't think this will make it into 8.2 -> defer to 9.0

@MorrisJobke MorrisJobke modified the milestones: 9.0-next, 8.2-current Sep 1, 2015
@oparoz
Copy link
Contributor Author

oparoz commented Sep 1, 2015

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.

@MorrisJobke
Copy link
Contributor

Feature freeze is in 3 weeks,

2 weeks ;) https://github.com/owncloud/core/wiki/Maintenance-and-Release-Schedule#owncloud-82

@oparoz
Copy link
Contributor Author

oparoz commented Sep 1, 2015

Ah, so that paragraph on the same page needs to be updated or is this an exception?

The feature freeze of each version will be one month before the release dates.

@MorrisJobke
Copy link
Contributor

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.

@scrutinizer-notifier
Copy link

A new inspection was created.

@oparoz
Copy link
Contributor Author

oparoz commented Sep 14, 2015

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

@oparoz oparoz modified the milestones: 8.2-current, 9.0-next Sep 14, 2015
@MorrisJobke
Copy link
Contributor

Superseeded by core branch PR in #19030

@MorrisJobke
Copy link
Contributor

@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

@oparoz
Copy link
Contributor Author

oparoz commented Sep 28, 2015

@MorrisJobke Added an issue in order to not forget.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 10, 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.

7 participants