array( 'class' => AccessControlBehavior::className(), 'rules' => array( array( 'allow' => \Yii::$app->user->checkAccess('systemLog'), 'actions' => ['list','reset'], 'roles' => ['@'] ), // deny all array( 'allow' => false ) ) ) ); } public function actionList() { $jlog = []; if (isset(\Yii::$app->log->targets['jsonErrorFile'])) { $target = \Yii::$app->log->targets['jsonErrorFile']; $jlog = file_get_contents($target->logFile); if ($jlog) { $jlog = json_decode('[' . mb_substr($jlog, 0, strlen($jlog) - 1) . ']'); } } else { $this->_status->setError(\Yii::t('api', 'jsonErrorFile logger target was not configured.')); } if (\Yii::$app->request->getIsAjax()) { return $this->_status->data = $jlog; } else { return $this->render('default.php', ['log' => $jlog]); } } public function actionReset() { if (isset(\Yii::$app->log->targets['jsonErrorFile'])) { $target = \Yii::$app->log->targets['jsonErrorFile']; if ($fp = @fopen($target->logFile, 'w+')) { @fclose($fp); $this->_status->setSuccess(\Yii::t('api', 'All log records have been reset')); } else { $this->_status->setError(\Yii::t('api', 'Can\'t open log files for write.')); } } else { $this->_status->setError(\Yii::t('api', 'jsonErrorFile logger target was not configured.')); } if (\Yii::$app->request->getIsAjax()) { return $this->answer(); } else { return $this->_status->toJson(); } } }