4 +-----------------------------------------------------------------------+
5 | program/include/bugs.inc |
7 | This file is part of the RoudCube Webmail client |
8 | Copyright (C) 2005-2007, RoudCube Dev - Switzerland |
9 | Licensed under the GNU GPL |
12 | Provide error handling and logging functions |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: bugs.inc 1291 2008-04-12 13:54:45Z thomasb $
24 * Error handling and logging functions
31 * Throw system error and show error page
33 * @param array Named parameters
34 * - code: Error code (required)
35 * - type: Error type [php|db|imap|javascript] (required)
36 * - message: Error message
37 * - file: File where error occured
38 * - line: Line where error occured
39 * @param boolean True to log the error
40 * @param boolean Terminate script execution
42 function raise_error($arg=array(), $log=false, $terminate=false)
44 global $__page_content, $CONFIG, $OUTPUT, $ERROR_CODE, $ERROR_MESSAGE;
46 // report bug (if not incompatible browser)
47 if ($log && $arg['type'] && $arg['message'])
50 // display error page and terminate script
53 $ERROR_CODE = $arg['code'];
54 $ERROR_MESSAGE = $arg['message'];
55 include("program/steps/error.inc");
62 * Report error according to configured debug_level
64 * @param array Named parameters
67 function log_bug($arg_arr)
70 $program = $arg_arr['type']=='xpath' ? 'XPath' : strtoupper($arg_arr['type']);
72 // write error to local log file
73 if ($CONFIG['debug_level'] & 1)
76 "[%s] %s Error: %s in %s on line %d\n",
77 date("d-M-Y H:i:s O", mktime()),
83 if (empty($CONFIG['log_dir']))
84 $CONFIG['log_dir'] = INSTALL_PATH.'logs';
86 // try to open specific log file for writing
87 if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a'))
89 fwrite($fp, $log_entry);
94 // send error to PHPs error handler
95 trigger_error($arg_arr['message']);
99 // resport the bug to the global bug reporting system
100 if ($CONFIG['debug_level'] & 2)
102 // TODO: Send error via HTTP
105 // show error if debug_mode is on
106 if ($CONFIG['debug_level'] & 4)
108 print "<b>$program Error";
110 if (!empty($arg_arr['file']) && !empty($arg_arr['line']))
111 print " in $arg_arr[file] ($arg_arr[line])";
114 print nl2br($arg_arr['message']);