logVars of log target is not working

Hi All,
I am not able to use the logVars property of logging properly.
With this config:

[
                    'class' => 'common\components\log\ExceptionFileTarget',
                    'levels' => ['exception'],
                    'logFile' => '@runtime/logs/error.logstash.log',
                    'exportInterval' => 1,
],

I am getting an output which contains $_SERVER array, which is as per expectation

{
"timestamp":"2020-10-15T12:46:54+00:00",
"ip":"-",
"userId":"-",
"sessionId":"-",
"level":"exception",
"category":"customException",
"text":"[],
"$_SERVER":"["LANG" => "Eng, "LC_ALL" => "Some other value"]"
}

But with this config:

[
                    'class' => 'common\components\log\ExceptionFileTarget',
                    'levels' => ['exception'],
                    'logVars' => ['_SERVER.LC_ALL'],
                    'logFile' => '@runtime/logs/error.logstash.log',
                    'exportInterval' => 1,
],

I am not getting the $_SERVER variable at all.

I was expecting the output to be:

{
"timestamp":"2020-10-15T12:46:54+00:00",
"ip":"-",
"userId":"-",
"sessionId":"-",
"level":"exception",
"category":"customException",
"text":"[],
"$_SERVER":"["LC_ALL" => "Some other value"]"
}

Am I missing something? Why is the $_SERVER array completely missing from the log?

Interesting. Sounds like a bug to me. Would you please report it via github issues?

Please do take a look: https://github.com/yiisoft/yii2/issues/18335

1 Like