LogsController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use backend\models\Logs;
  5. class LogsController extends BaseController
  6. {
  7. /**
  8. * 日志列表数据
  9. */
  10. public function actionList()
  11. {
  12. $model = new Logs();
  13. $result = $model->getList(Yii::$app->request->post());
  14. if ($result['code']) {
  15. return $this->outJson(1, $result['data']);
  16. } else {
  17. return $this->outJson(0, [], $result['message']);
  18. }
  19. }
  20. /**
  21. * 查看日志
  22. */
  23. public function actionView()
  24. {
  25. $path = trim(Yii::$app->request->get('path'));
  26. $file = Yii::$app->getRuntimePath() . '/logs/app.log';
  27. if (is_file($file)) {
  28. $contents = @file_get_contents($file);
  29. return $this->outJson(1, ['contents' => $contents]);
  30. }
  31. return $this->outJson(0, ['contents' => ''], '文件不存在');
  32. }
  33. /**
  34. * 清空日志
  35. */
  36. public function actionTruncate()
  37. {
  38. $path = trim(Yii::$app->request->get('path'));
  39. $file = Yii::$app->getRuntimePath() . '/logs/app.log';
  40. if (is_file($file)) {
  41. @file_put_contents($file, '');
  42. return $this->outJson(1);
  43. }
  44. return $this->outJson(0);
  45. }
  46. }