| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace backend\controllers;
- use Yii;
- use backend\models\Logs;
- class LogsController extends BaseController
- {
- /**
- * 日志列表数据
- */
- public function actionList()
- {
- $model = new Logs();
- $result = $model->getList(Yii::$app->request->post());
- if ($result['code']) {
- return $this->outJson(1, $result['data']);
- } else {
- return $this->outJson(0, [], $result['message']);
- }
- }
-
- /**
- * 查看日志
- */
- public function actionView()
- {
- $path = trim(Yii::$app->request->get('path'));
- $file = Yii::$app->getRuntimePath() . '/logs/app.log';
- if (is_file($file)) {
- $contents = @file_get_contents($file);
- return $this->outJson(1, ['contents' => $contents]);
- }
- return $this->outJson(0, ['contents' => ''], '文件不存在');
- }
- /**
- * 清空日志
- */
- public function actionTruncate()
- {
- $path = trim(Yii::$app->request->get('path'));
- $file = Yii::$app->getRuntimePath() . '/logs/app.log';
- if (is_file($file)) {
- @file_put_contents($file, '');
- return $this->outJson(1);
- }
- return $this->outJson(0);
- }
- }
|