A
A
Andrew2017-03-25 18:45:48
PHP
Andrew, 2017-03-25 18:45:48

[PSR-3, monolog] How to properly build a logging, logging and error reporting system on a website?

To begin with, I know about the PSR-3 standard and the monolog library. The project itself is quite large, so I think this library is a good fit. But some points are still not clear.
For example, take registration / authorization (or other processing of user data). Previously, all input errors (for example, validation errors) were written to the $_SESSION superglobal array, then a redirect was made to the same page to clear the POST data (so that F5 could not send the form again), then the errors were output to the template and the session was cleared, which If the errors were not looming all the time. Now I began to pay attention that in some articles / videos / books of this kind errors are put into exceptions, and the text from this exception is simply shown to the user.

  • Is this practice normal?
  • How does this approach deal with clearing the form from POST?
  • Is the monolog library suitable for this task, or is it only for logging, but not intended for displaying errors to users?
  • A small digression in the question, but in different places they write / say differently about where to validate the data: controller, model or a separate component?
  • If data is validated in the controller, then where to intercept it in case of exceptions? I assume that it is better to do this in a separate component, and intercept already in the controller?

I am also interested in the practice of logging errors / non-standard situations / and other simple events in the project. It is clear here that monolog seems to be suitable, but it is not entirely clear how this should be combined with the exception mechanism? I can assume that with a possible error an exception is thrown and the same error is logged below through the library? Or should there be another mechanism?
Well, the last question, which probably belongs to the category of personal practices. How do you generally organize logging on your website/project? That is, write what errors in the logs, what errors by email, maybe you still use some delivery methods. If you are writing to log files, then what directory structure and the log file itself are you doing depending on the type of error / message? This is where best practices come into play.
Thank you for your attention.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmitriy, 2017-03-26
@dmitriylanets

1. an exception is thrown when the behavior is not planned, as a rule, we put all the work of the application into try catch and:
```
try{
$aplication->start();
}
catch(Exception $e){
$logger->error($e->getMessage());
return new Response("Error in the application")
}
```
As a rule, we add information to the log in production, in the development version, you can throw everything on the screen.
Also, in the functional, you can log useful information $logger->debug(), $logger->info(), etc. The
logging level is set when the application is initialized

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question