My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php

class Noginn_Log_Writer_Growl extends Zend_Log_Writer_Abstract
{
/**
* Maps logging priorities to Growl notification priority
* @var array
*/
protected $_priorityTypes = array(
Zend_Log::EMERG => Noginn_Growl::PRIORITY_EMERGENCY,
Zend_Log::ALERT => Noginn_Growl::PRIORITY_HIGH,
Zend_Log::CRIT => Noginn_Growl::PRIORITY_HIGH,
Zend_Log::ERR => Noginn_Growl::PRIORITY_HIGH,
Zend_Log::WARN => Noginn_Growl::PRIORITY_NORMAL,
Zend_Log::NOTICE => Noginn_Growl::PRIORITY_MODERATE,
Zend_Log::INFO => Noginn_Growl::PRIORITY_LOW,
Zend_Log::DEBUG => Noginn_Growl::PRIORITY_LOW
);

/**
* The default Growl notification priority for un-mapped priorities
* @var string
*/
protected $_defaultPriorityType = Noginn_Growl::PRIORITY_NORMAL;

/**
* Maps logging priorities to Growl notification title
* @var array
*/
protected $_priorityTitles = array(
Zend_Log::EMERG => 'Emergency',
Zend_Log::ALERT => 'Alert',
Zend_Log::CRIT => 'Critical',
Zend_Log::ERR => 'Error',
Zend_Log::WARN => 'Warning',
Zend_Log::NOTICE => 'Notice',
Zend_Log::INFO => 'Info',
Zend_Log::DEBUG => 'Debug'
);

/**
* The default Growl notification title for un-mapped priority
* @var string
*/
protected $_defaultPriorityTitle = 'Log';

/**
* Flag indicating whether the log writer is enabled
* @var boolean
*/
protected $_enabled = true;

protected $_growl;

/**
* Class constructor
*
* @param Noginn_Growl $growl The instance of the Growl component to use
*/
public function __construct(Noginn_Growl $growl)
{
$this->setGrowl($growl);

if (php_sapi_name()=='cli') {
$this->setEnabled(false);
}
}

public function setGrowl($growl)
{
foreach ($this->_priorityTitles as $name) {
$growl->addNotification($name);
}

$this->_growl = $growl;
}

public function getGrowl()
{
return $this->_growl;
}

/**
* Enable or disable the log writer.
*
* @param boolean $enabled Set to TRUE to enable the log writer
* @return boolean The previous value.
*/
public function setEnabled($enabled)
{
$previous = $this->_enabled;
$this->_enabled = $enabled;
return $previous;
}

/**
* Determine if the log writer is enabled.
*
* @return boolean Returns TRUE if the log writer is enabled.
*/
public function getEnabled()
{
return $this->_enabled;
}

/**
* Formatting is not possible on this writer
*
* @return void
*/
public function setFormatter($formatter)
{
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception(get_class() . ' does not support formatting');
}

/**
* Send a Growl notification with the log message
*
* @param array $event The event data
* @return void
*/
protected function _write($event)
{
if (!$this->getEnabled()) {
return;
}

if (array_key_exists($event['priority'],$this->_priorityTypes)) {
$type = $this->_priorityTypes[$event['priority']];
} else {
$type = $this->_defaultPriorityType;
}

if (array_key_exists($event['priority'],$this->_priorityTitles)) {
$title = $this->_priorityTitles[$event['priority']];
} else {
$title = $this->_defaultPriorityTitle;
}

$growl = $this->getGrowl();
$growl->notify($title, $title, $event['message'], $type);
}
}

Change log

r6 by tom.gra...@noginn.com on Sep 21, 2008   Diff
Updated comments.
Go to: 
Project members, sign in to write a code review

Older revisions

r5 by tom.gra...@noginn.com on Sep 21, 2008   Diff
Added Growl log writer.
All revisions of this file

File info

Size: 3876 bytes, 144 lines
Powered by Google Project Hosting