20
20
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
21
21
* @author William Durand <william.durand1@gmail.com>
22
22
*/
23
- class PropelLogger
23
+ class PropelLogger implements \BasicLogger
24
24
{
25
25
/**
26
26
* @var LoggerInterface
@@ -30,14 +30,17 @@ class PropelLogger
30
30
/**
31
31
* @var array
32
32
*/
33
- protected $ queries ;
33
+ protected $ queries = array () ;
34
34
35
35
/**
36
36
* @var Stopwatch
37
37
*/
38
38
protected $ stopwatch ;
39
39
40
- private $ isPrepared ;
40
+ /**
41
+ * @var Boolean
42
+ */
43
+ private $ isPrepared = false ;
41
44
42
45
/**
43
46
* Constructor.
@@ -48,87 +51,59 @@ class PropelLogger
48
51
public function __construct (LoggerInterface $ logger = null , Stopwatch $ stopwatch = null )
49
52
{
50
53
$ this ->logger = $ logger ;
51
- $ this ->queries = array ();
52
54
$ this ->stopwatch = $ stopwatch ;
53
- $ this ->isPrepared = false ;
54
55
}
55
56
56
57
/**
57
- * A convenience function for logging an alert event.
58
- *
59
- * @param mixed $message the message to log.
58
+ * {@inheritDoc}
60
59
*/
61
60
public function alert ($ message )
62
61
{
63
- if (null !== $ this ->logger ) {
64
- $ this ->logger ->alert ($ message );
65
- }
62
+ $ this ->log ($ message , 'alert ' );
66
63
}
67
64
68
65
/**
69
- * A convenience function for logging a critical event.
70
- *
71
- * @param mixed $message the message to log.
66
+ * {@inheritDoc}
72
67
*/
73
68
public function crit ($ message )
74
69
{
75
- if (null !== $ this ->logger ) {
76
- $ this ->logger ->critical ($ message );
77
- }
70
+ $ this ->log ($ message , 'crit ' );
78
71
}
79
72
80
73
/**
81
- * A convenience function for logging an error event.
82
- *
83
- * @param mixed $message the message to log.
74
+ * {@inheritDoc}
84
75
*/
85
76
public function err ($ message )
86
77
{
87
- if (null !== $ this ->logger ) {
88
- $ this ->logger ->error ($ message );
89
- }
78
+ $ this ->log ($ message , 'err ' );
90
79
}
91
80
92
81
/**
93
- * A convenience function for logging a warning event.
94
- *
95
- * @param mixed $message the message to log.
82
+ * {@inheritDoc}
96
83
*/
97
84
public function warning ($ message )
98
85
{
99
- if (null !== $ this ->logger ) {
100
- $ this ->logger ->warning ($ message );
101
- }
86
+ $ this ->log ($ message , 'warning ' );
102
87
}
103
88
104
89
/**
105
- * A convenience function for logging an critical event.
106
- *
107
- * @param mixed $message the message to log.
90
+ * {@inheritDoc}
108
91
*/
109
92
public function notice ($ message )
110
93
{
111
- if (null !== $ this ->logger ) {
112
- $ this ->logger ->notice ($ message );
113
- }
94
+ $ this ->log ($ message , 'notice ' );
114
95
}
115
96
116
97
/**
117
- * A convenience function for logging an critical event.
118
- *
119
- * @param mixed $message the message to log.
98
+ * {@inheritDoc}
120
99
*/
121
100
public function info ($ message )
122
101
{
123
- if (null !== $ this ->logger ) {
124
- $ this ->logger ->info ($ message );
125
- }
102
+ $ this ->log ($ message , 'info ' );
126
103
}
127
104
128
105
/**
129
- * A convenience function for logging a debug event.
130
- *
131
- * @param mixed $message the message to log.
106
+ * {@inheritDoc}
132
107
*/
133
108
public function debug ($ message )
134
109
{
@@ -152,8 +127,40 @@ public function debug($message)
152
127
153
128
if ($ add ) {
154
129
$ this ->queries [] = $ message ;
155
- if (null !== $ this ->logger ) {
156
- $ this ->logger ->debug ($ message );
130
+ $ this ->log ($ message , 'debug ' );
131
+ }
132
+ }
133
+
134
+ /**
135
+ * {@inheritDoc}
136
+ */
137
+ public function log ($ message , $ severity = null )
138
+ {
139
+ if (null !== $ this ->logger ) {
140
+ $ message = is_string ($ message ) ? $ message : var_export ($ message , true );
141
+
142
+ switch ($ severity ) {
143
+ case 'alert ' :
144
+ $ this ->logger ->alert ($ message );
145
+ break ;
146
+ case 'crit ' :
147
+ $ this ->logger ->critical ($ message );
148
+ break ;
149
+ case 'err ' :
150
+ $ this ->logger ->error ($ message );
151
+ break ;
152
+ case 'warning ' :
153
+ $ this ->logger ->warning ($ message );
154
+ break ;
155
+ case 'notice ' :
156
+ $ this ->logger ->notice ($ message );
157
+ break ;
158
+ case 'info ' :
159
+ $ this ->logger ->info ($ message );
160
+ break ;
161
+ case 'debug ' :
162
+ default :
163
+ $ this ->logger ->debug ($ message );
157
164
}
158
165
}
159
166
}
0 commit comments