Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Levels for Custom Log Targets are not working #3766

Closed
TheFox opened this issue Feb 1, 2019 · 6 comments
Closed

Error Levels for Custom Log Targets are not working #3766

TheFox opened this issue Feb 1, 2019 · 6 comments

Comments

@TheFox
Copy link

TheFox commented Feb 1, 2019

Description

Consider this settings:

// app.php
return [
    'components' => [
        'log' => function () {
            $logConfig = craft\helpers\App::logConfig();

            // Email Target
            $logConfig['targets'][] = [
                'class' => EmailTarget::class,
                'levels' => ['warning', 'error'],
                'message' => [
                    'from' => ['error@example.com'],
                    'to' => ['error@example.com'],
                    'subject' => 'My Project ERROR',
                ],
                'logVars' => [],
            ];

            // Instantiate and return the component.
            return Craft::createObject($logConfig);
        },
    ],
];

Then, very often, I get emails with the following text:

2019-02-01 10:37:14.312 +0100 [info][craft\queue\QueueLogBehavior::beforeExec]  [96] Deleting stale template caches (attempt: 1) - Started
...

This should not happen since I have only subscribed warning and error.

Steps to reproduce

  1. Create custom log target.
  2. Wait for it.

Additional info

  • Craft version: Craft Pro 3.1.6.1
  • PHP version: 7.2.13
  • Database driver & version: MySQL 5.5.5
@brandonkelly
Copy link
Member

This is going to be a Yii bug, if not just an issue with how you’re configuring it. Can you please report it over at https://github.com/yiisoft/yii2/issues ?

@TheFox
Copy link
Author

TheFox commented Feb 2, 2019

Ok, I'll. Thanks.

@erktime
Copy link

erktime commented Jun 5, 2019

@brandonkelly I recently had the same issue. I don't believe this is a YII bug but instead a Craft bug. Craft's custom QueueLogBehavior modifies all log targets setup for the site. Look at your code:
https://github.com/craftcms/cms/blob/develop/src/queue/QueueLogBehavior.php#L89

You override the except and levels for every log target, not just the default file target that craft uses by default.

@brandonkelly
Copy link
Member

Doh, you are correct @erktime. 😞

@brandonkelly
Copy link
Member

brandonkelly commented Jun 5, 2019

Fixed for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#34e1fef8ee10754014ab1bc986b682ef5f0fa4a9",
  "...": "..."
}

Then run composer update.

@erktime
Copy link

erktime commented Jun 6, 2019

Team work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants