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

Separate core error logging from standard LoggerInterface #8241

Merged

Conversation

robbieaverill
Copy link
Contributor

@robbieaverill robbieaverill commented Jul 4, 2018

Up for discussion!

At a high level:

  • Rename the existing error handler implementation
  • Register the default handler implementation as LoggerInterface for general purpose use
  • Allow MonologErrorHandler to accept multiple loggers (includes deprecation of setHandler in favour of pushHandler)
  • Update documentation, fix some typos in related docs/code

I've tested the following situations:

  • Injector::inst()->get(LoggerInterface::class)->debug('Hello') levels are all logged to whatever handlers are defined for LoggerInterface (default: none)
    • Tested with file stream logger configured
    • Tested with "Messages" tab log collection in lekoala/silverstripe-debugbar
  • Throwing an exception is handled by the SilverStripe error handler (CLI/browser)
  • Throwing an exception is sent to the defined loggers for LoggerInterface (e.g. if using a file/stream logger)
  • Logging PSR-3 errors via LoggerInterface doesn't get included in SilverStripe's error handlers
  • Explicit log entries via LoggerInterface.errorhandler do get included in SilverStripe's error handler (previously the default behaviour)

Considerations:

  • Do we want to provide a NoopLoggerTestState test state in framework that is configured by default to replace any custom log handlers that user code has defined, e.g. file logs? We could push a NullHandler by default

Resolves #8044

@dhensby
Copy link
Contributor

dhensby commented Jul 4, 2018

Do we want to provide a NoopLoggerTestState test state in framework that is configured by default to replace any custom log handlers that user code has defined, e.g. file logs? We could push a NullHandler by default

quite possibly, yes - but maybe it would be good to actually log the test logs somewhere?

I'd probably just log it to standard out...

@robbieaverill
Copy link
Contributor Author

quite possibly, yes - but maybe it would be good to actually log the test logs somewhere?
I'd probably just log it to standard out...

The problem with that is that your phpunit runs fill up with stdout log calls from various parts of the codebase.

How about we configure a NullHandler for unit tests by default, which devs can remove via config if they want to. We might even be able to use the --verbose flag from phpunit to control this as well...

@robbieaverill
Copy link
Contributor Author

Rebased on top of 4 since there were some changes underneath. I've also added a ->setLoggers(array $loggers) method in case someone wants to clear them

Copy link
Contributor

@maxime-rainville maxime-rainville left a comment

Choose a reason for hiding this comment

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

I like the change conceptually.

Did not review the detail of the PR or try running it locally. If there's a consensus this is a good thing, I'd be keen to peer review it.

@robbieaverill
Copy link
Contributor Author

Thanks for having a look. Remaining would be to add something for unit test logging config/handlers. Not sure it'd block review and merge of this though - it could be done as a follow up

@sminnee
Copy link
Member

sminnee commented Feb 8, 2019

Just going to flag that right now logging is broken if you use Raygun. Gonna fix that with some bandaids but we should get this into 4.4!

@robbieaverill
Copy link
Contributor Author

robbieaverill commented Feb 10, 2019

Thanks @sminnee. To recap, I think the follow up action required is to decide whether to automatically configure a null handler for user configured logging when running unit tests (override user configured handlers) or to log test output somewhere by default, e.g. a /var/tmp/silverstripe-tests.log file or something like that.

I don't think stdout logging is a good idea TBH because it'll pollute phpunit test results.

Can we get a vote on it from @silverstripe/core-team?

🚀 : disable test logging by default
👀 : enable test logging to a file by default

@robbieaverill
Copy link
Contributor Author

robbieaverill commented Feb 22, 2019

Two weeks for a vote on that, seems like the consensus is to remove (user configured project) logging from tests by default.

@ScopeyNZ
Copy link
Member

ScopeyNZ commented Apr 4, 2019

Looks like there's general good thoughts towards this PR in 4.4. I'll merge it now then :)

@ScopeyNZ ScopeyNZ merged commit a9d57f5 into silverstripe:4 Apr 4, 2019
@ScopeyNZ ScopeyNZ deleted the pulls/4.3/separate-logging branch April 4, 2019 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CONTROL] Logging before httpError will cause HTML to be added and output as plaintext
6 participants