Project

General

Profile

Bug #15734 ยป log_message.txt

Example for priority adjustable log_message function - Nic Bernstein, 09/19/2024 03:43 PM

 
1
/****f* util/log_message
2
* NAME
3
*   log_message  - Sends a string to syslog with specified priority.
4
* INPUTS
5
*   $message     - string containing the syslog message.
6
*   $priority    - priority to send with, defaults to 'info'
7
* RESULT
8
*   null
9
******/
10
function log_message($message, $priority = 'info') {
11
	global $g;
12
	$page = $_SERVER['SCRIPT_NAME'];
13
	if (empty($page)) {
14
		$files = get_included_files();
15
		$page = basename($files[0]);
16
	}
17
        switch (strtolower($priority)) {
18
                case str_starts_with($priority, 'emerg'):
19
                        $pri = LOG_EMERG;
20
                        break;
21
                case 'alert':
22
                        $pri = LOG_ALERT;
23
                        break;
24
                case str_starts_with($priority, 'crit'):
25
                        $pri = LOG_CRIT;
26
                        break;
27
                case str_starts_with($priority, 'err'):
28
                        $pri = LOG_ERR;
29
                        break;
30
                case str_starts_with($priority, 'warn'):
31
                        $pri = LOG_WARN;
32
                        break;
33
                case 'notice':
34
                        $pri = LOG_NOTICE;
35
                        break;
36
                case str_starts_with($priority, 'debug'):
37
                        $pri = LOG_DEBUG;
38
                        break;
39
                default:
40
                        $pri = LOG_INFO;
41
                        break;
42
        }
43
	syslog($pri, "$page: $message");
44
	if (g_get('debug')) {
45
		syslog(LOG_WARNING, var_export(debug_backtrace()));
46
	}
47
	return;
48
}
    (1-1/1)