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

Improve logging #1633

Merged
merged 4 commits into from
Nov 13, 2018
Merged

Improve logging #1633

merged 4 commits into from
Nov 13, 2018

Conversation

tobyzerner
Copy link
Contributor

Fixes #1619
Fixes #991

Changes proposed in this pull request:

  • Catch Throwables so that we handle and log internal PHP errors too
  • Stop logging errors that use a custom view (eg. 404 - RouteNotFound)
  • Log errors that occur in the API stack

See commit messages for more details.

This is not a definitive implementation for optimal error handling and logging. Ideally we should have a more advanced error handling solution like the one referenced in #1619. But I thought it would be good to implement a least-resistance stopgap in the meantime.

Reviewers should focus on:
Is this acceptable for the purposes of beta 8.

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run php vendor/bin/phpunit).

Having a custom view implies that a friendly message is displayed to
the user, in which case we can bet that the exception won't need to be
"debugged" per se.
This takes place only in the FallbackExceptionHandler. Having a custom
exception handler implies that a friendly message is displayed in the
API response, in which case we can bet that the exception won't need to
be "debugged" per se.

if (! $this->debug) {
$this->logger->error($e);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only log in debug mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought was that in debug mode you can see the error displayed when you encounter it, and therefore no need to log it. I suppose it'd be simpler to just log everything regardless though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, errors that occur in the forum stack don't get logged when debug mode is on, because they go through the HandleErrorsWithWhoops middleware. Whatever we do, it should be consistent between the forum/API stacks. Should we add logging to the Whoops middleware or keep things as-is?

Copy link
Member

Choose a reason for hiding this comment

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

Let's always use the log, it makes it easier when errors aren't clearly visible when developing. Although this does not always happen in our own code, it might still happen in third party extensions and without logs the cause of white pages etc might be less clear. Let's stick to always logging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree. Always logging means a) no surprises and b) persistence.

Copy link
Contributor

@franzliedke franzliedke left a comment

Choose a reason for hiding this comment

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

I am fine with this.

What I would like to see in beta.9:

  • One middleware (always enabled) that converts all known exception types with custom views to pretty error pages, always.
  • Another middleware (either Whoops or pretty pages) that a) displays the exceptions and b) logs them. (The logging could even be a separate middleware that re-throws the exceptions, unless that messes with the stack traces.)

IMO, there is no need for NotFound and similar exceptions to ever be handled with the fallback error handling (Whoops or pretty pages) - we are just using the exception mechanism to handle known error cases.

@franzliedke franzliedke merged commit 68c6638 into master Nov 13, 2018
@franzliedke franzliedke deleted the tz/improve-logging branch November 13, 2018 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants