I'm getting a lot of noise in the logs from requests that are auto generated from browsers and spiders (like favico.ico, robots.txt, /home /news etc) that doesn't actually have any endpoints.

These get caught by index.php and throws

[yii\web\HttpException:404] yii\web\NotFoundHttpException: Template not found: new in /app/vendor/craftcms/cms/src/controllers/TemplatesController.php:93"

Which is causing a tremendous amount of noise. I would never consider a 404 a real error, so I would like to not log this at all in Craft (I can use access log aggregation for this).

However, I'm not sure how to go about it. I have already created a custom log component, to remove the logging of all server variables on error, and send outputs to stderr (because of docker), with yii2-streamlog.

My log config is as follows:

    'components' => [
        'log' => function() {
            return Craft::createObject([
                'class' => yii\log\Dispatcher::class,
                'targets' => [
                        'class' => codemix\streamlog\Target::class,
                        'url' => 'php://stderr',
                        'levels' => Logger::LEVEL_ERROR | Logger::LEVEL_WARNING,
                        'logVars' => []

  • Seems like adding a 'except' => ['yii\web\HttpException:404'] to the target removes it from my streamlog
    – jishi
    Nov 19 '19 at 21:18

Those should not be logged in web.log when running Craft 3.x, but rather in the web404s.log -- assuming you don't have devMode on (which it shouldn't be on for production...)

Vide: Zen and the Art of Craft CMS Log File Reading

Also should you really want to customize things, it's not hard to do with Craft CMS, check out: Creating a Custom Logger for Craft CMS

  • I don't have devMode on, but I have changed to a the streamlog, but don't understand why that would enable it? I just can't have a file since I'm running in AWS ECS as a container. But I assume I could add an except config somehow to remove the yii\web\HttpException:404 namespace?
    – jishi
    Nov 19 '19 at 20:57
  • I added a section on Monolog as a Logger that I think answers what you're trying to do here: Creating a Custom Logger for Craft CMS (see the 'except' key/value) Nov 21 '19 at 18:24
  • Nice, Monolog seems like a more versatile setup than yii2-streamlog.
    – jishi
    Nov 21 '19 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.