-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
mod_syslog_syslog.php
130 lines (110 loc) · 2.57 KB
/
mod_syslog_syslog.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php';
/**
* Class to manage logging to syslog
*/
class mod_syslog_syslog extends LogHandler implements LogHandlerInterface
{
public $code = 'syslog';
/**
* Return name of logger
*
* @return string Name of logger
*/
public function getName()
{
return 'Syslogd';
}
/**
* Version of the module ('x.y.z' or 'dolibarr' or 'experimental' or 'development')
*
* @return string
*/
public function getVersion()
{
return 'dolibarr';
}
/**
* Content of the info tooltip.
*
* @return false|string
*/
public function getInfo()
{
global $langs;
return $langs->trans('OnlyWindowsLOG_USER');
}
/**
* Is the module active ?
*
* @return int
*/
public function isActive()
{
global $conf;
// This function does not exists on some ISP (Ex: Free in France)
if (!function_exists('openlog')) {
return 0;
}
return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_SYSLOG) ? 1 : 0; // Set SYSLOG_DISABLE_LOGHANDLER_SYSLOG to 1 to disable this loghandler
}
/**
* Return array of configuration data
*
* @return array Return array of configuration data
*/
public function configure()
{
global $langs;
return array(
array(
'constant' => 'SYSLOG_FACILITY',
'name' => $langs->trans('SyslogFacility'),
'default' => 'LOG_USER'
)
);
}
/**
* Return if configuration is valid
*
* @return array Array of errors. Empty array if ok.
*/
public function checkConfiguration()
{
global $conf, $langs;
$errors = array();
$facility = constant($conf->global->SYSLOG_FACILITY);
if ($facility) {
// Only LOG_USER supported on Windows
if (!empty($_SERVER["WINDIR"])) {
$facility = constant('LOG_USER');
}
dol_syslog("admin/syslog: facility ".$facility);
} else {
$errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility);
}
return $errors;
}
/**
* Export the message
*
* @param array $content Array containing the info about the message
* @return void
*/
public function export($content)
{
global $conf;
if (!empty($conf->global->MAIN_SYSLOG_DISABLE_SYSLOG)) {
return; // Global option to disable output of this handler
}
if (!empty($conf->global->SYSLOG_FACILITY)) { // Example LOG_USER
$facility = constant($conf->global->SYSLOG_FACILITY);
} else {
$facility = constant('LOG_USER');
}
// (int) is required to avoid error parameter 3 expected to be long
openlog('dolibarr', LOG_PID | LOG_PERROR, (int) $facility);
syslog($content['level'], $content['message']);
closelog();
}
}