Syslog.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Syslog log writer.
  4. *
  5. * @package Kohana
  6. * @category Logging
  7. * @author Jeremy Bush
  8. * @copyright (c) Kohana Team
  9. * @license https://koseven.ga/LICENSE.md
  10. */
  11. class Kohana_Log_Syslog extends Log_Writer {
  12. /**
  13. * @var string The syslog identifier
  14. */
  15. protected $_ident;
  16. /**
  17. * Creates a new syslog logger.
  18. *
  19. * @link http://www.php.net/manual/function.openlog
  20. *
  21. * @param string $ident syslog identifier
  22. * @param int $facility facility to log to
  23. * @return void
  24. */
  25. public function __construct($ident = 'KohanaPHP', $facility = LOG_USER)
  26. {
  27. $this->_ident = $ident;
  28. // Open the connection to syslog
  29. openlog($this->_ident, LOG_CONS, $facility);
  30. }
  31. /**
  32. * Writes each of the messages into the syslog.
  33. *
  34. * @param array $messages
  35. * @return void
  36. */
  37. public function write(array $messages)
  38. {
  39. foreach ($messages as $message)
  40. {
  41. syslog($message['level'], $message['body']);
  42. if (isset($message['additional']['exception']))
  43. {
  44. syslog(Log_Writer::$strace_level, $message['additional']['exception']->getTraceAsString());
  45. }
  46. }
  47. }
  48. /**
  49. * Closes the syslog connection
  50. *
  51. * @return void
  52. */
  53. public function __destruct()
  54. {
  55. // Close connection to syslog
  56. closelog();
  57. }
  58. }