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

An ability to have wildcards in yii\log\Target::$maskVars array #20295

Open
xcopy opened this issue Dec 9, 2024 · 2 comments
Open

An ability to have wildcards in yii\log\Target::$maskVars array #20295

xcopy opened this issue Dec 9, 2024 · 2 comments

Comments

@xcopy
Copy link
Contributor

xcopy commented Dec 9, 2024

Let's assume that I have the following configuration:

// config/components/log.php
return [
    'targets' => [
        [
            'class' => 'yii\log\FileTarget',
            'levels' => ['error', 'warning'],
            'maskVars' => [
                '_SERVER.AUTH_GOOGLE_TOKEN',
                '_SERVER.AUTH_FACEBOOK_TOKEN',
                '_SERVER.AUTH_TWITTER_TOKEN',
                '_SERVER.AUTH_GITHUB_TOKEN',
                '_SERVER.AUTH_APPLE_TOKEN',
                '_SERVER.AUTH_MICROSOFT_TOKEN',
                '_SERVER.AUTH_MICROSOFT_TOKEN',
                // ...

                '_POST.LoginForm.password',
                '_POST.ChangePassword.password',
                '_POST.ResetPasswordForm.password',
                '_POST.ResetPasswordForm.password_repeat',
                // ...
            ]
        ]
    ]
]

And the context information to be logged respectively:

$_SERVER = [
    'AUTH_GOOGLE_TOKEN' => '***',
    'AUTH_FACEBOOK_TOKEN' => '***',
    'AUTH_TWITTER_TOKEN' => '***',
    'AUTH_GITHUB_TOKEN' => '***',
    'AUTH_APPLE_TOKEN' => '***',
    'AUTH_MICROSOFT_TOKEN' => '***',
    'AUTH_MICROSOFT_TOKEN' => '***',
]

$_POST = [
    'LoginForm' => [
        'password' => '***',
    ],
    'ResetPasswordForm' => [
        'password' => '***',
        'password_repeat' => '***',
    ]
]

But what if instead of tens (or hundreds) predefined variables we will only have a few entries, e.g.

'maskVars' => [
    '_SERVER.*TOKEN',
    '_POST.*.password',
]

Is it worth it? Would be convenient, huh?

@samdark
Copy link
Member

samdark commented Dec 9, 2024

👍 Indeed, it would be convenient. Do you have time for a pull request?

@xcopy
Copy link
Contributor Author

xcopy commented Dec 10, 2024

Yeah, sure. I'll do my best.

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

No branches or pull requests

2 participants