You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OC\Log;
  28. use OC\SystemConfig;
  29. use OCP\ILogger;
  30. use OCP\Log\IWriter;
  31. class Syslog extends LogDetails implements IWriter {
  32. protected $levels = [
  33. ILogger::DEBUG => LOG_DEBUG,
  34. ILogger::INFO => LOG_INFO,
  35. ILogger::WARN => LOG_WARNING,
  36. ILogger::ERROR => LOG_ERR,
  37. ILogger::FATAL => LOG_CRIT,
  38. ];
  39. public function __construct(SystemConfig $config) {
  40. parent::__construct($config);
  41. openlog($config->getValue('syslog_tag', 'Nextcloud'), LOG_PID | LOG_CONS, LOG_USER);
  42. }
  43. public function __destruct() {
  44. closelog();
  45. }
  46. /**
  47. * write a message in the log
  48. * @param string $app
  49. * @param string $message
  50. * @param int $level
  51. */
  52. public function write(string $app, $message, int $level) {
  53. $syslog_level = $this->levels[$level];
  54. syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level));
  55. }
  56. }