Masks sensitive data keys in logs

Hi there,

Is there any inbuilt extension to mask sensitive data keys in logs

Nothing built into Yii but this is a good package. yupmin/magoo - Packagist

Oh jeez, yeah! So, like, in Yii2, there is this built-in thing — not some separate extension, just part of the core logging system. It’s called maskVars, and you set it up in your log target config.

Basically, when you configure your logging component, you add 'maskVars' with an array of sensitive keys like 'password', 'secret', or whatever. Yii then automatically replaces those values with '***' in the logs so your sensitive info doesn’t get exposed.

Here’s a quick example you can toss into your config:

'components' => [
    'log' => [
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning', 'info'],
                'maskVars' => ['password', 'password_confirm', 'secret'],
            ],
        ],
    ],
],

So yeah, no worries — Yii’s got your back on hiding stuff like passwords in logs without extra extensions or hacks. Just remember to add the keys you wanna hide to maskVars. Pretty sweet, right?

2 Likes