Ik ben bezig geweest met het schtijven van mijn eigen error class. De class werkt prima in zend studio als ik ga debuggen.
Maar als ik de pagina op (een vers geinstalleerde) webserver gooi word er niets in de log file gegooit.
hier mijn code:
en de code om een error te veroorzaken:
en natuurlijk de output :
Ook php.net geeft verder wienig info.
oftewel... I'm lost
Maar als ik de pagina op (een vers geinstalleerde) webserver gooi word er niets in de log file gegooit.
hier mijn code:
PHP:
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
| <?php /* * Description: * Class to handle php and custom errors. * * Configuration: * In Constructor * * Usage: * Create a error object. At creation, the handler will be activated * $eh = new Error(); * Any php error will be handled by the object. * * throw up a error : * trigger_error( 'error msg' , E_USER_NOTICE ); * */ class Error { var $logFilename; // Private String name (or path) to logfile var $mailAddress; // Private String Email address of webmaster var $errorToFile; // Private boolean flag var $warningToFile; // Private boolean flag var $noticeToFile; // Private boolean flag var $errorToMail; // Private boolean flag var $warningToMail; // Private boolean flag var $noticeToMail; // Private boolean flag /* * description: * * Visibility: Constructor * * Args: * none * * Return: * boolean */ function Error(){ $this->setMailAddress( 'recipients@email.com' ); $this->setFilename( 'Error_log.log' ); $this->setFlags( true, true, true, true, true, true ); //Log errors to file?, Log warnings to file?, Log notices to file?, Send errors via mail?, Send warnings via mail?, Send notices via mail? $this->setHandler(); return true; } /* * description: actual error handler called by the engine * * Visibility: Public * * Args: * String error_type * String error_msg * String error_file * int error_line * String error_context * * Return: * boolean */ function errorHandler($error_type, $error_msg, $error_file, $error_line, $error_context){ switch( $error_type ){ case E_ERROR: case E_USER_ERROR: if( $this->errorToFile ){ if( $this->logFilename == '' ){ error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 0); } else{error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 3, $this->logFilename); } } if( $this->errorToMail ){ $this->mailError($error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10)); } echo $error_msg,' (error type ',$error_type,' in ',$error_file,' on line ',$error_line,') [context: ',$error_context,']<br />'; exit; break; case E_WARNING: case E_USER_WARNING: if( $this->warningToFile ){ if( $this->logFilename == '' ){ error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 0); } else { error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 3, $this->logFilename); } } if( $this->warningToMail ){ $this->mailError($error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10)); } echo $error_msg,' (error type ',$error_type,' in ',$error_file,' on line ',$error_line,') [context: ',$error_context,']<br />'; break; case E_NOTICE: case E_USER_NOTICE: if( $this->noticeToFile ){ if( $this->logFilename == '' ){ error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 0); } else{ error_log( $error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10), 3, $this->logFilename); } } if( $this->noticeToMail ){ $this->mailError($error_msg . ' (error type ' . $error_type . ' in ' . $error_file . ' on line ' . $error_line . ') [context: ' . $error_context . ']' . chr(10)); } echo $error_msg,' (error type ',$error_type,' in ',$error_file,' on line ',$error_line,') [context: ',$error_context,']<br />'; break; } return true; } /* * description: set the error handler for the php engine * * Visibility: Public * * Args: * none * * Return: * boolean */ function setHandler(){ set_error_handler( array( &$this, 'errorHandler' ) ); return true; } /* * description: restore the default error handler for the php engine * * Visibility: Public * * Args: * none * * Return: * boolean */ function restoreHandler(){ restore_error_handler(); return true; } /* * description: set the various flags in order: * Log errors to file? * Log warnings to file? * Log notices to file? * Send errors via mail? * Send warnings via mail? * Send notices via mail? * * Visibility: Public * * Args: * boolean errorToFile * boolean warningToFile * boolean noticeToFile * boolean errorToMail * boolean warningToMail * boolean noticeToMail * * Return: * boolean */ function setFlags( $errorToFile, $warningToFile, $noticeToFile, $errorToMail, $warningToMail, $noticeToMail){ $this->errorToFile = $errorToFile; //Log errors to file? $this->warningToFile = $warningToFile; //Log warnings to file? $this->noticeToFile = $noticeToFile; //Log notices to file? $this->errorToMail = $errorToMail; //Send errors via mail? $this->warningToMail = $warningToMail; //Send warnings via mail? $this->noticeToMail = $noticeToMail; //Send notices via mail? return true; } /* * description: Set the email address of the webmaster (used to send errors to) * * Visibility: Public * * Args: * String address (Email adress) * * Return: * boolean */ function setMailAddress( $address ){ $this->mailAddress = $address; return true; } /* * description: Set the filename of the logfile (complete path) * * Visibility: Public * * Args: * String filename (path) * * Return: * boolean */ function setFilename( $filename ){ $this->logFilename = $filename; return true; } /* * description: prints backtrace of potential error * * Visibility: Public * * Args: * none * * Return: * boolean */ function showBacktrace(){ debug_backtrace(); return true; } /* * description: Send email to webmaster * * Visibility: Private * * Args: * none * * Return: * boolean */ function mailError( $mail_body ){ $headers ='From: clsErrorHandler' . "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\r\n"; $subject = 'Error Report'; $body = $mail_body; mail( $this->mailAddress, $subject, $body, $headers ); return true; } } ?> |
en de code om een error te veroorzaken:
PHP:
1
2
3
4
5
| <?php include 'Error.class.php'; $e = &new Error; trigger_error( 'error msg' , E_USER_NOTICE ); ?> |
en natuurlijk de output :
ik ben al een tijdje aan t googlen maar het enige waar ik op uit kom zijn codes precies zoals ik het doe. Ook zijn er naar mijn weten geen entry's in php.ini die dit zouden kunnen restricten....Notice: error msg in c:\apache\htdocs\test.php on line 4
Ook php.net geeft verder wienig info.
oftewel... I'm lost
[ Voor 8% gewijzigd door Verwijderd op 13-07-2004 20:47 ]