ralusnom
ralusnom

Reputation: 135

Symfony not showing PDO exceptions in production log

If my application has no connection to the database (postgres), it ends with the default error page showing the infamous error in prod-mode:

Oops! An Error Occurred
The server returned a "500 Internal Server Error".

In dev mode I see the error:

PDOException > Exception  > ConnectionException
An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused

These causes are not displayed in the logs. Neither server nor php logs. The only thing I see there is

172.19.0.1 - - [30/Oct/2020:09:58:25 +0000] "GET / HTTP/1.1" 500 831

This is my monolog configuration:

monolog:
  handlers:
    main:
     type: fingers_crossed
     action_level: debug
     handler: nested

  nested:
     type: stream
     path: php://stdout
     level: debug

Btw, I'm logging everything to stdout.

So, how do I get these errors to the log?

(Symfony 5.1, docker, apache2)

Upvotes: 1

Views: 658

Answers (1)

Nicolai Fröhlich
Nicolai Fröhlich

Reputation: 52493

The debug verbosity is the highest verbosity.

The fingers crossed handler only forwards logs with a verbosity equal to or higher than the action_level to the specified handler.

So in your case it would only forward debug messages.

Use action_level: error for the fingers crossed handler and clear your cache afterwards to forward all logs to the nested handler in your case.

More information can be found in the documentation Handlers that Modify Log Entries of the fingers crossed handler.

Upvotes: 2

Related Questions