CSysLogRoute.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * CSysLogRoute class file.
  4. *
  5. * @author miramir <gmiramir@gmail.com>
  6. * @author resurtm <resurtm@gmail.com>
  7. * @link http://www.yiiframework.com/
  8. * @copyright 2008-2014 Yii Software LLC
  9. * @license http://www.yiiframework.com/license/
  10. */
  11. /**
  12. * CSysLogRoute dumps log messages to syslog.
  13. *
  14. * @author miramir <gmiramir@gmail.com>
  15. * @author resurtm <resurtm@gmail.com>
  16. * @package system.logging
  17. * @since 1.1.16
  18. */
  19. class CSysLogRoute extends CLogRoute
  20. {
  21. /**
  22. * @var string syslog identity name.
  23. */
  24. public $identity;
  25. /**
  26. * @var integer syslog facility name.
  27. */
  28. public $facility=LOG_SYSLOG;
  29. /**
  30. * Sends log messages to syslog.
  31. * @param array $logs list of log messages.
  32. */
  33. protected function processLogs($logs)
  34. {
  35. static $syslogLevels=array(
  36. CLogger::LEVEL_TRACE=>LOG_DEBUG,
  37. CLogger::LEVEL_WARNING=>LOG_WARNING,
  38. CLogger::LEVEL_ERROR=>LOG_ERR,
  39. CLogger::LEVEL_INFO=>LOG_INFO,
  40. CLogger::LEVEL_PROFILE=>LOG_DEBUG,
  41. );
  42. openlog($this->identity,LOG_ODELAY|LOG_PID,$this->facility);
  43. foreach($logs as $log)
  44. syslog($syslogLevels[$log[1]],$this->formatLogMessage(str_replace("\n",', ',$log[0]),$log[1],$log[2],$log[3]));
  45. closelog();
  46. }
  47. }