Customizing Monolog HTML formatter for email

Monolog can send emails when there’s an error, but in the provided HTML formatter I missed the REQUEST_URI and REMOTE_ADDR that triggered the error.

Some info is in the exceptions section, but not always and needs horizontal scrolling in the email client 🙂

So I just replicated the HtmlFormatter and added some lines (dirty hacks).

Added service class

 <service id="app.monolog.formatter.html" class="App\Service\MonologEmailFormatter" public="false" />

Change formatter service ID

# app/config/config_prod.yml
    type: swift_mailer
    from_email: ""
    to_email: [""]
    subject: 'Error'
    level: error
    formatter: custom.monolog.formatter.html
    content_type: text/html

UPDATE: You might be interested in


Hack Symfony2 database password for admin

Had to get in the admin of a Symfony2 version 2.6 app and I had only code and database access.
I just added some rows to the loginAction() method to get the salt and password for my own plaintext password.

public function loginAction(Request $request) {
    $user = new User();
    $plainPassword = 'YOUR_pass_HERE';
    $encoder = $this->container->get('security.password_encoder');
    echo 'Salt:<br>'.$user->getSalt();
    echo '<br>Password:<br>'.$encoder->encodePassword($user, $plainPassword);

    // loginAction code continues ....


Symfony2 password change
Salt and encoded password for user

Changed the values in the database and login was successful.
You could also flush and persist the new user if you would like, but username needs to be set.
For more help visit the awesome docs page at