Answer the question
In order to leave comments, you need to log in
[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.
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question