PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/rucrm/log4php.debug/appenders/LoggerAppenderSyslog.php

https://code.google.com/p/vtiger-ru-fork/
PHP | 85 lines | 38 code | 7 blank | 40 comment | 2 complexity | 001f8a491bf37c2dd27b1f94a7df2c47 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * log4php is a PHP port of the log4j java logging package.
  4. *
  5. * <p>This framework is based on log4j (see {@link http://jakarta.apache.org/log4j log4j} for details).</p>
  6. * <p>Design, strategies and part of the methods documentation are developed by log4j team
  7. * (Ceki Gülcü as log4j project founder and
  8. * {@link http://jakarta.apache.org/log4j/docs/contributors.html contributors}).</p>
  9. *
  10. * <p>PHP port, extensions and modifications by VxR. All rights reserved.<br>
  11. * For more information, please see {@link http://www.vxr.it/log4php/}.</p>
  12. *
  13. * <p>This software is published under the terms of the LGPL License
  14. * a copy of which has been included with this distribution in the LICENSE file.</p>
  15. *
  16. * @package log4php
  17. * @subpackage appenders
  18. */
  19. /**
  20. * @ignore
  21. */
  22. if (!defined('LOG4PHP_DIR')) define('LOG4PHP_DIR', dirname(__FILE__) . '/..');
  23. require_once(LOG4PHP_DIR . '/LoggerAppenderSkeleton.php');
  24. require_once(LOG4PHP_DIR . '/LoggerLevel.php');
  25. require_once(LOG4PHP_DIR . '/LoggerLog.php');
  26. /**
  27. * Log events using php {@link PHP_MANUAL#syslog} function.
  28. *
  29. * Levels are mapped as follows:
  30. * - <b>level &gt;= FATAL</b> to LOG_ALERT
  31. * - <b>FATAL &gt; level &gt;= ERROR</b> to LOG_ERR
  32. * - <b>ERROR &gt; level &gt;= WARN</b> to LOG_WARNING
  33. * - <b>WARN &gt; level &gt;= INFO</b> to LOG_INFO
  34. * - <b>INFO &gt; level &gt;= DEBUG</b> to LOG_DEBUG
  35. *
  36. * @author VxR <vxr@vxr.it>
  37. * @version $Revision: 1.11 $
  38. * @package log4php
  39. * @subpackage appenders
  40. */
  41. class LoggerAppenderSyslog extends LoggerAppenderSkeleton {
  42. /**
  43. * Constructor
  44. *
  45. * @param string $name appender name
  46. */
  47. function LoggerAppenderSyslog($name)
  48. {
  49. $this->LoggerAppenderSkeleton($name);
  50. }
  51. function activateOptions()
  52. {
  53. define_syslog_variables();
  54. $this->closed = false;
  55. }
  56. function close()
  57. {
  58. closelog();
  59. $this->closed = true;
  60. }
  61. function append($event)
  62. {
  63. $level = $event->getLevel();
  64. $message = $event->getRenderedMessage();
  65. if ($level->isGreaterOrEqual(LoggerLevel::getLevelFatal())) {
  66. syslog(LOG_ALERT, $message);
  67. } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelError())) {
  68. syslog(LOG_ERR, $message);
  69. } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelWarn())) {
  70. syslog(LOG_WARNING, $message);
  71. } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelInfo())) {
  72. syslog(LOG_INFO, $message);
  73. } elseif ($level->isGreaterOrEqual(LoggerLevel::getLevelDebug())) {
  74. syslog(LOG_DEBUG, $message);
  75. }
  76. }
  77. }
  78. ?>