Unable to append to log file

My app that’s using Yii 2 advanced template is not able to write into the app.log file. Both the frontend/runtime/logs folder and its contents (app.log file) have the www-data has the owner (user and group). I’ve tried setting full permissions 777 on both the folder and app.log file just to debug, but the app isn’t still able to write to the log file.

This is my current config in /frontend/config/main.php

'log' => [
    'traceLevel' => YII_DEBUG ? 3 : 0,
    'targets' => [
            'class' => 'yii\log\FileTarget',
            'levels' => ['error', 'warning'],
            'class' => 'yii\log\EmailTarget',
            'mailer' => 'mailer',
            'levels' => ['error', 'warning'],
            'message' => [
                'from' => 'admin@mydomain.com',
                'to' => ['logs@mydomain.com'],
                'subject' => 'Error / Warning',

These are my permissions inside the runtime folder:

drwxrwxr-x 2 www-data www-data 4096 Jan  10  2018 debug
drwxrwxrwx 2 www-data www-data 4096 Apr 28 15:46 logs

and for the app.log file:

rwxrwxrwx 1 www-data www-data 174248 Jan 10 2018 app.log

This is the error that I get when the app fails to write into the log file:

[warning][yii\log\Dispatcher::dispatch] Unable to send log via yii\log\FileTarget: Exception (Invalid
Configuration) 'yii\base\InvalidConfigException' with message 'Unable
to append to log file:

in /var/www/html/my-yii2-advanced/vendor/yiisoft/yii2/log/FileTarget.php:109

Stack trace:
#0 /var/www/html/my-yii2-advanced/vendor/yiisoft/yii2/log/Target.php(133):
yii\log\Target->collect(Array, true)
#2 /var/www/html/my-yii2-advanced/vendor/yiisoft/yii2/log/Logger.php(177):
yii\log\Dispatcher->dispatch(Array, true)
#4 [internal function]:
#5 {main}

I finally managed to fix this issue. The issue happened while compiling the container’s image using Docker. Basically, the permissions were being overridden and the owner wasn’t “www-data”. I just had to add the proper owner permissions to “www-data” in the Dockerfile.