Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LogSettingsController.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * @author Georg Ehrke <georg@owncloud.com>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Roeland Jago Douma <rullzer@owncloud.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @copyright Copyright (c) 2016, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Settings\Controller;
  26. use OCP\AppFramework\Controller;
  27. use OCP\AppFramework\Http;
  28. use OCP\AppFramework\Http\JSONResponse;
  29. use OCP\AppFramework\Http\StreamResponse;
  30. use OCP\IL10N;
  31. use OCP\IRequest;
  32. use OCP\IConfig;
  33. /**
  34. * Class LogSettingsController
  35. *
  36. * @package OC\Settings\Controller
  37. */
  38. class LogSettingsController extends Controller {
  39. /**
  40. * @var \OCP\IConfig
  41. */
  42. private $config;
  43. /**
  44. * @var \OCP\IL10N
  45. */
  46. private $l10n;
  47. /**
  48. * @param string $appName
  49. * @param IRequest $request
  50. * @param IConfig $config
  51. */
  52. public function __construct($appName,
  53. IRequest $request,
  54. IConfig $config,
  55. IL10N $l10n) {
  56. parent::__construct($appName, $request);
  57. $this->config = $config;
  58. $this->l10n = $l10n;
  59. }
  60. /**
  61. * set log level for logger
  62. *
  63. * @param int $level
  64. * @return JSONResponse
  65. */
  66. public function setLogLevel($level) {
  67. if ($level < 0 || $level > 4) {
  68. return new JSONResponse([
  69. 'message' => (string) $this->l10n->t('log-level out of allowed range'),
  70. ], Http::STATUS_BAD_REQUEST);
  71. }
  72. $this->config->setSystemValue('loglevel', $level);
  73. return new JSONResponse([
  74. 'level' => $level,
  75. ]);
  76. }
  77. /**
  78. * get log entries from logfile
  79. *
  80. * @param int $count
  81. * @param int $offset
  82. * @return JSONResponse
  83. */
  84. public function getEntries($count=50, $offset=0) {
  85. return new JSONResponse([
  86. 'data' => \OC\Log\Owncloud::getEntries($count, $offset),
  87. 'remain' => count(\OC\Log\Owncloud::getEntries(1, $offset + $count)) !== 0,
  88. ]);
  89. }
  90. /**
  91. * download logfile
  92. *
  93. * @NoCSRFRequired
  94. *
  95. * @return StreamResponse
  96. */
  97. public function download() {
  98. $resp = new StreamResponse(\OC\Log\Owncloud::getLogFilePath());
  99. $resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"');
  100. return $resp;
  101. }
  102. }