I am really new to Yii2 and I am trying to print a simple string to the console. However, no matter what I do, I can’t really make it work. I am not sure if I have my Setup wrong or if I simply don’t use the functions as intended.
My TeamController.php
was generated by Gii
and the function I want to simply check if my code runs through looks like this:
<?php namespace appcontrollers; use Yii; use appmodelsTeam; use yiidataActiveDataProvider; use yiiwebController; use yiiwebNotFoundHttpException; use yiifiltersVerbFilter; use yiilogLogger; use yiihelpersVarDumper; /** * Creates a new Team model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { VarDumper::dump('Hello world'); //<-- Does not print to console. Yii::debug('start calculating average revenue'); //<-- Does not print to console. $model = new Team(); if ($this->request->isPost) { if ($model->load($this->request->post()) && $model->save()) { return $this->redirect(['view', 'idteam' => $model->id]); } } else { $model->loadDefaultValues(); } return $this->render('create', [ 'model' => $model, ]); }
UPDATE
Changed some configurations in the web.php
within the config directory.:
'log' => [ 'targets' => [ [ 'class' => 'yiilogFileTarget', 'levels' => ['error', 'warning', 'trace', 'info'], 'logVars' => [], 'logFile' => '@runtime/webapp/logs/myfile.log', ], ], ],
Am I forgetting something or are other configurations wrong?
Advertisement
Answer
You can try to set flushInterval
and exportInterval
'log' => [ 'flushInterval' => 1, // <-- here 'targets' => [ [ 'class' => 'yiilogFileTarget', 'levels' => ['error', 'warning', 'trace', 'info'], 'logVars' => [], 'logFile' => '@runtime/webapp/logs/myfile.log', 'exportInterval' => 1, // <-- and here ], ], ]
sourse: https://yii2-cookbook-test.readthedocs.io/logging-problems-and-solutions/