log.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. OC_Log::$object = new \OC\Log();
  15. class OC_Log {
  16. public static $object;
  17. const DEBUG=0;
  18. const INFO=1;
  19. const WARN=2;
  20. const ERROR=3;
  21. const FATAL=4;
  22. static private $level_funcs = array(
  23. self::DEBUG => 'debug',
  24. self::INFO => 'info',
  25. self::WARN => 'warning',
  26. self::ERROR => 'error',
  27. self::FATAL => 'emergency',
  28. );
  29. static public $enabled = true;
  30. static protected $class = null;
  31. /**
  32. * write a message in the log
  33. * @param string $app
  34. * @param string $message
  35. * @param int $level
  36. */
  37. public static function write($app, $message, $level) {
  38. if (self::$enabled) {
  39. $context = array('app' => $app);
  40. $func = array(self::$object, self::$level_funcs[$level]);
  41. call_user_func($func, $message, $context);
  42. }
  43. }
  44. }