1: <?php
2: /**
3: * Horde Log package
4: *
5: * @author Mike Naberezny <mike@maintainable.com>
6: * @author Chuck Hagenbuch <chuck@horde.org>
7: * @category Horde
8: * @license http://www.horde.org/licenses/bsd BSD
9: * @package Log
10: * @subpackage Handlers
11: */
12:
13: /**
14: * @author Mike Naberezny <mike@maintainable.com>
15: * @author Chuck Hagenbuch <chuck@horde.org>
16: * @category Horde
17: * @license http://www.horde.org/licenses/bsd BSD
18: * @package Log
19: * @subpackage Handlers
20: */
21: class Horde_Log_Handler_Scribe extends Horde_Log_Handler_Base
22: {
23: /**
24: * Scribe client.
25: *
26: * @var Horde_Scribe_Client
27: */
28: protected $_scribe;
29:
30: /**
31: * Formats the log message before writing.
32: *
33: * @var Horde_Log_Formatter
34: */
35: protected $_formatter;
36:
37: /**
38: * Options to be set by setOption().
39: *
40: * @var array
41: */
42: protected $_options = array(
43: 'addNewline' => false,
44: 'category' => 'default',
45: 'ident' => ''
46: );
47:
48: /**
49: * Constructor.
50: *
51: * @param Horde_Scribe_Client $scribe Scribe client.
52: * @param Horde_Log_Formatter $formatter Log formatter.
53: */
54: public function __construct(Horde_Scribe_Client $scribe,
55: Horde_Log_Formatter $formatter = null)
56: {
57: $this->_formatter = is_null($formatter)
58: ? new Horde_Log_Formatter_Simple()
59: : $formatter;
60: $this->_scribe = $scribe;
61: }
62:
63: /**
64: * Write a message to the log.
65: *
66: * @param array $event Log event.
67: *
68: * @return boolean True.
69: */
70: public function write($event)
71: {
72: if (!empty($this->_options['ident'])) {
73: $event['message'] = $this->_options['ident'] . ' ' . $event['message'];
74: }
75:
76: $category = isset($event['category'])
77: ? $event['category']
78: : $this->_options['category'];
79:
80: $message = $this->_formatter->format($event);
81: if (!$this->_options['addNewline']) {
82: $message = rtrim($message);
83: }
84:
85: $this->_scribe->log($category, $message);
86:
87: return true;
88: }
89:
90: }
91: