phpyii2

How to create anonymous function in view for getting data?


I use httpclient to save logs of the project

https://github.com/yiisoft/yii2-httpclient/blob/master/docs/guide/usage-logging.md

Log file creates in folder which is property for

'logFile' => '@runtime/logs/http-request.log'

I want to make the path dynamic, depending on provider I use. F.e. I wait for '@runtime/logs/provider1/http-request.log' or '@runtime/logs/provider2/http-request.log' depending on the provider which logs I want to save. The question is how to declare anonymous function in attribute logFile to get data from another class?


Solution

  • The component config in config/main.php is a the default config for your needs but you could access to the log component dynamically using eg:

    Yii::$app->log->targets['logFile'] = '@runtime/logs/http-request.log';