source: subversion/trunk/roundcubemail/program/include/bugs.inc @ 1683

Last change on this file since 1683 was 1683, checked in by alec, 5 years ago
  • added options to use syslog instead of log file (#1484850)
  • added Logging & Debugging section in Installer
  • fixed config from $_POST for next installer steps saving
  • fixed and re-enabled debug_level setting in installer
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/include/bugs.inc                                              |
6 |                                                                       |
7 | This file is part of the RoudCube Webmail client                      |
8 | Copyright (C) 2005-2007, RoudCube Dev - Switzerland                   |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Provide error handling and logging functions                        |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22
23/**
24 * Error handling and logging functions
25 *
26 * @package Core
27 */
28
29
30/**
31 * Throw system error and show error page
32 *
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
41 */
42function raise_error($arg=array(), $log=false, $terminate=false)
43  {
44  global $__page_content, $CONFIG, $OUTPUT, $ERROR_CODE, $ERROR_MESSAGE;
45 
46  // report bug (if not incompatible browser)
47  if ($log && $arg['type'] && $arg['message'])
48    log_bug($arg);
49
50  // display error page and terminate script
51  if ($terminate)
52    {
53    $ERROR_CODE = $arg['code'];
54    $ERROR_MESSAGE = $arg['message'];
55    include("program/steps/error.inc");
56    exit;
57    }
58  }
59
60
61/**
62 * Report error according to configured debug_level
63 *
64 * @param array Named parameters
65 * @see raise_error()
66 */
67function log_bug($arg_arr)
68{
69  global $CONFIG;
70  $program = $arg_arr['type']=='xpath' ? 'XPath' : strtoupper($arg_arr['type']);
71
72  // write error to local log file
73  if ($CONFIG['debug_level'] & 1)
74  {
75    $log_entry = sprintf(
76      "[%s] %s Error: %s in %s on line %d\n",
77      date("d-M-Y H:i:s O", mktime()),
78      $program,
79      $arg_arr['message'],
80      $arg_arr['file'],
81      $arg_arr['line']);
82                 
83    if (empty($CONFIG['log_dir']))
84      $CONFIG['log_dir'] = INSTALL_PATH.'logs';
85     
86    // try to open specific log file for writing
87    if ($CONFIG['log_driver'] == 'syslog')
88    {
89      syslog(LOG_ERR, $log_entry);
90    }
91    else if ($fp = @fopen($CONFIG['log_dir'].'/errors', 'a'))
92    {
93      // log_driver == 'file' is the default, assumed here.
94      fwrite($fp, $log_entry);
95      fclose($fp);
96    }
97    else
98    {
99      // send error to PHPs error handler
100      trigger_error($arg_arr['message']);
101    }
102  }
103
104  // resport the bug to the global bug reporting system
105  if ($CONFIG['debug_level'] & 2)
106  {
107    // TODO: Send error via HTTP
108  }
109
110  // show error if debug_mode is on
111  if ($CONFIG['debug_level'] & 4)
112  {
113    print "<b>$program Error";
114
115    if (!empty($arg_arr['file']) && !empty($arg_arr['line']))
116      print " in $arg_arr[file] ($arg_arr[line])";
117
118    print ":</b>&nbsp;";
119    print nl2br($arg_arr['message']);
120    print '<br />';
121    flush();
122  }
123}
124
125?>
Note: See TracBrowser for help on using the repository browser.