syslog.php 846 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. class OC_Log_Syslog {
  9. static protected $levels = array(
  10. OC_Log::DEBUG => LOG_DEBUG,
  11. OC_Log::INFO => LOG_INFO,
  12. OC_Log::WARN => LOG_WARNING,
  13. OC_Log::ERROR => LOG_ERR,
  14. OC_Log::FATAL => LOG_CRIT,
  15. );
  16. /**
  17. * Init class data
  18. */
  19. public static function init() {
  20. openlog('ownCloud', LOG_PID | LOG_CONS, LOG_USER);
  21. // Close at shutdown
  22. register_shutdown_function('closelog');
  23. }
  24. /**
  25. * write a message in the log
  26. * @param string $app
  27. * @param string $message
  28. * @param int level
  29. */
  30. public static function write($app, $message, $level) {
  31. $syslog_level = self::$levels[$level];
  32. syslog($syslog_level, '{'.$app.'} '.$message);
  33. }
  34. }