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 2025 2008-10-30 09:15:01Z alec $
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 = strtoupper($arg_arr['type']);
72 // write error to local log file
73 if ($CONFIG['debug_level'] & 1)
75 $post_query = ($_SERVER['REQUEST_METHOD'] == 'POST' ? '?_task='.urlencode($_POST['_task']).'&_action='.urlencode($_POST['_action']) : '');
76 $log_entry = sprintf("[%s] %s Error: %s%s (%s %s)\n",
77 date("d-M-Y H:i:s O", mktime()),
80 $arg_arr['file'] ? sprintf(' in %s on line %d', $arg_arr['file'], $arg_arr['line']) : '',
81 $_SERVER['REQUEST_METHOD'],
82 $_SERVER['REQUEST_URI'] . $post_query);
84 if (empty($CONFIG['log_dir']))
85 $CONFIG['log_dir'] = INSTALL_PATH.'logs';
87 // try to open specific log file for writing
88 if ($CONFIG['log_driver'] == 'syslog')
90 syslog(LOG_ERR, $log_entry);
92 else if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a'))
94 // log_driver == 'file' is the default, assumed here.
95 fwrite($fp, $log_entry);
100 // send error to PHPs error handler
101 trigger_error($arg_arr['message']);
105 // resport the bug to the global bug reporting system
106 if ($CONFIG['debug_level'] & 2)
108 // TODO: Send error via HTTP
111 // show error if debug_mode is on
112 if ($CONFIG['debug_level'] & 4)
114 print "<b>$program Error";
116 if (!empty($arg_arr['file']) && !empty($arg_arr['line']))
117 print " in $arg_arr[file] ($arg_arr[line])";
120 print nl2br($arg_arr['message']);