-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsurfconext.exception.class.inc
53 lines (45 loc) · 1.51 KB
/
surfconext.exception.class.inc
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
<?php
/**
* @file
* Definition of SurfConextException.
*/
class SurfConextException extends Exception {
const SEVERITY_HIGH = 80;
const SEVERITY_NORMAL = 50;
const SEVERITY_LOW = 20;
/**
* The constructor.
*
* @param string $msg
* The exception message.
* @param integer $severity
* The severity of the message, as per RFC 3164. Possible values are
* WATCHDOG_ERROR, WATCHDOG_WARNING, etc.
* @param boolean $log
* Specify TRUE to log exception in Drupals watchdog. Default is TRUE.
*/
public function __construct($msg = '', $severity = self::SEVERITY_NORMAL, $log = TRUE) {
$msg = empty($msg) ? 'SURFconext exception was thrown.' : $msg;
if ($severity >= self::SEVERITY_NORMAL) {
$log_serverity = $severity >= self::SEVERITY_HIGH ? WATCHDOG_CRITICAL : WATCHDOG_NOTICE;
$levels = watchdog_severity_levels();
// Get backtrace when you can.
$backtrace = $this->getTraceAsString();
if ($log) {
watchdog(
'SURFConext exception',
'@message (Exception thrown (severity: @severity) on line @line, in @file)<br />Partial backtrace: <pre>@backtrace</pre>',
array(
'@severity' => $levels[$log_serverity],
'@message' => $msg,
'@line' => $this->getLine(),
'@file' => $this->getFile(),
'@backtrace' => empty($backtrace) ? 'no backtrace available' : $backtrace,
),
$log_serverity
);
}
}
parent::__construct($msg);
}
}