syslog.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @author Andreas Fischer <bantu@owncloud.com>
  4. * @author Bart Visscher <bartv@thisnet.nl>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. class OC_Log_Syslog {
  25. static protected $levels = array(
  26. OC_Log::DEBUG => LOG_DEBUG,
  27. OC_Log::INFO => LOG_INFO,
  28. OC_Log::WARN => LOG_WARNING,
  29. OC_Log::ERROR => LOG_ERR,
  30. OC_Log::FATAL => LOG_CRIT,
  31. );
  32. /**
  33. * Init class data
  34. */
  35. public static function init() {
  36. openlog('ownCloud', LOG_PID | LOG_CONS, LOG_USER);
  37. // Close at shutdown
  38. register_shutdown_function('closelog');
  39. }
  40. /**
  41. * write a message in the log
  42. * @param string $app
  43. * @param string $message
  44. * @param int $level
  45. */
  46. public static function write($app, $message, $level) {
  47. $syslog_level = self::$levels[$level];
  48. syslog($syslog_level, '{'.$app.'} '.$message);
  49. }
  50. }