1 | <?php |
---|
2 | /* |
---|
3 | * $Id: MojaviLogAdapter.php 521 2007-01-05 13:29:36Z heltem $ |
---|
4 | * |
---|
5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
16 | * |
---|
17 | * This software consists of voluntary contributions made by many individuals |
---|
18 | * and is licensed under the LGPL. For more information please see |
---|
19 | * <http://propel.phpdb.org>. |
---|
20 | */ |
---|
21 | |
---|
22 | /** |
---|
23 | * Mojavi logging adapter for propel |
---|
24 | * |
---|
25 | * @author Brandon Keepers <brandon@opensoul.org> |
---|
26 | * @version $Revision: 521 $ |
---|
27 | * @package propel.logger |
---|
28 | */ |
---|
29 | class MojaviLogAdapter implements BasicLogger { |
---|
30 | |
---|
31 | /** |
---|
32 | * Instance of mojavi logger |
---|
33 | */ |
---|
34 | private $logger = null; |
---|
35 | |
---|
36 | /** |
---|
37 | * constructor for setting up Mojavi log adapter |
---|
38 | * |
---|
39 | * @param ErrorLog $logger instance of Mojavi error log obtained by |
---|
40 | * calling LogManager::getLogger(); |
---|
41 | */ |
---|
42 | public function __construct($logger = null) |
---|
43 | { |
---|
44 | $this->logger = $logger; |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * A convenience function for logging an alert event. |
---|
49 | * |
---|
50 | * @param mixed $message String or Exception object containing the message |
---|
51 | * to log. |
---|
52 | */ |
---|
53 | public function alert($message) |
---|
54 | { |
---|
55 | $this->log($message, 'alert'); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * A convenience function for logging a critical event. |
---|
60 | * |
---|
61 | * @param mixed $message String or Exception object containing the message |
---|
62 | * to log. |
---|
63 | */ |
---|
64 | public function crit($message) |
---|
65 | { |
---|
66 | $this->log($message, 'crit'); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * A convenience function for logging an error event. |
---|
71 | * |
---|
72 | * @param mixed $message String or Exception object containing the message |
---|
73 | * to log. |
---|
74 | */ |
---|
75 | public function err($message) |
---|
76 | { |
---|
77 | $this->log($message, 'err'); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * A convenience function for logging a warning event. |
---|
82 | * |
---|
83 | * @param mixed $message String or Exception object containing the message |
---|
84 | * to log. |
---|
85 | */ |
---|
86 | public function warning($message) |
---|
87 | { |
---|
88 | $this->log($message, 'warning'); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | /** |
---|
93 | * A convenience function for logging an critical event. |
---|
94 | * |
---|
95 | * @param mixed $message String or Exception object containing the message |
---|
96 | * to log. |
---|
97 | */ |
---|
98 | public function notice($message) |
---|
99 | { |
---|
100 | $this->log($message, 'notice'); |
---|
101 | } |
---|
102 | /** |
---|
103 | * A convenience function for logging an critical event. |
---|
104 | * |
---|
105 | * @param mixed $message String or Exception object containing the message |
---|
106 | * to log. |
---|
107 | */ |
---|
108 | public function info($message) |
---|
109 | { |
---|
110 | $this->log($message, 'info'); |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * A convenience function for logging a debug event. |
---|
115 | * |
---|
116 | * @param mixed $message String or Exception object containing the message |
---|
117 | * to log. |
---|
118 | */ |
---|
119 | public function debug($message) |
---|
120 | { |
---|
121 | $this->log($message, 'debug'); |
---|
122 | } |
---|
123 | |
---|
124 | /** |
---|
125 | * Primary method to handle logging. |
---|
126 | * |
---|
127 | * @param mixed $message String or Exception object containing the message |
---|
128 | * to log. |
---|
129 | * @param int $severity The numeric severity. Defaults to null so that no |
---|
130 | * assumptions are made about the logging backend. |
---|
131 | */ |
---|
132 | public function log($message, $severity = null) |
---|
133 | { |
---|
134 | if (is_null($this->logger)) |
---|
135 | $this->logger = LogManager::getLogger('propel'); |
---|
136 | |
---|
137 | switch($severity) |
---|
138 | { |
---|
139 | case 'crit': |
---|
140 | $method = 'fatal'; |
---|
141 | break; |
---|
142 | case 'err': |
---|
143 | $method = 'error'; |
---|
144 | break; |
---|
145 | case 'alert': |
---|
146 | case 'warning': |
---|
147 | $method = 'warning'; |
---|
148 | break; |
---|
149 | case 'notice': |
---|
150 | case 'info': |
---|
151 | $method = 'info'; |
---|
152 | break; |
---|
153 | case 'debug': |
---|
154 | default: |
---|
155 | $method = 'debug'; |
---|
156 | } |
---|
157 | |
---|
158 | // get a backtrace to pass class, function, file, & line to Mojavi logger |
---|
159 | $trace = debug_backtrace(); |
---|
160 | |
---|
161 | // call the appropriate Mojavi logger method |
---|
162 | $this->logger->{$method} ( |
---|
163 | $message, |
---|
164 | $trace[2]['class'], |
---|
165 | $trace[2]['function'], |
---|
166 | $trace[1]['file'], |
---|
167 | $trace[1]['line'] |
---|
168 | ); |
---|
169 | } |
---|
170 | } |
---|