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.

log.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /**
  9. * logging utilities
  10. *
  11. * Log is saved by default at data/owncloud.log using OC_Log_Owncloud.
  12. * Selecting other backend is done with a config option 'log_type'.
  13. */
  14. class OC_Log {
  15. const DEBUG=0;
  16. const INFO=1;
  17. const WARN=2;
  18. const ERROR=3;
  19. const FATAL=4;
  20. static public $enabled = true;
  21. static protected $class = null;
  22. /**
  23. * write a message in the log
  24. * @param string $app
  25. * @param string $message
  26. * @param int level
  27. */
  28. public static function write($app, $message, $level) {
  29. if (self::$enabled) {
  30. if (!self::$class) {
  31. self::$class = 'OC_Log_'.ucfirst(OC_Config::getValue('log_type', 'owncloud'));
  32. call_user_func(array(self::$class, 'init'));
  33. }
  34. $log_class=self::$class;
  35. $log_class::write($app, $message, $level);
  36. }
  37. }
  38. //Fatal errors handler
  39. public static function onShutdown() {
  40. $error = error_get_last();
  41. if($error) {
  42. //ob_end_clean();
  43. self::write('PHP', $error['message'] . ' at ' . $error['file'] . '#' . $error['line'], self::FATAL);
  44. } else {
  45. return true;
  46. }
  47. }
  48. // Uncaught exception handler
  49. public static function onException($exception) {
  50. self::write('PHP',
  51. $exception->getMessage() . ' at ' . $exception->getFile() . '#' . $exception->getLine(),
  52. self::FATAL);
  53. }
  54. //Recoverable errors handler
  55. public static function onError($number, $message, $file, $line) {
  56. if (error_reporting() === 0) {
  57. return;
  58. }
  59. self::write('PHP', $message . ' at ' . $file . '#' . $line, self::WARN);
  60. }
  61. }