PageRenderTime 73ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/system/classes/Kohana/Log/Syslog.php

https://bitbucket.org/alexpozdnyakov/kohana
PHP | 65 lines | 24 code | 7 blank | 34 comment | 1 complexity | 6b812885cbe844bcdf31f312b450c0d8 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php defined('SYSPATH') OR die('No direct script access.');
  2. /**
  3. * Syslog log writer.
  4. *
  5. * @package Kohana
  6. * @category Logging
  7. * @author Jeremy Bush
  8. * @copyright (c) 2012 Kohana Team
  9. * @license http://kohanaframework.org/license
  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. } // End Kohana_Log_Syslog