Log - Target - Email and recurring emails with the same error

I have log - target:

'error' => [
    'class' => 'yii\log\EmailTarget',
    'levels' => ['error', 'warning'],
    'except' => ['yii\web\HttpException:404'],
    'message' => [
        'from' => ['XXXXXXX'],
        'to' => ['XXXXXXX'],
        'subject' => 'XXXXXX - error',
    ],
],

It will send me an email whenever an application error/warning occurs. It’s OK.

The problem is a “long duration” error (for example database down, but it could be anything else).
It sends an email for every visit the website.
With high traffic = hundreds of emails with the same error during one minute.

How prevent recurring emails with the same error?

For production it’s much better to use something like https://sentry.io/welcome/ (they have OpenSource version) or https://rollbar.com/. They’s both recording each error instance with full context, getting you a list of the most repeating errors and sending summary emails.