dolibarr  16.0.1
mod_syslog_syslog.php
1 <?php
2 
3 require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php';
4 
9 {
10  public $code = 'syslog';
11 
17  public function getName()
18  {
19  return 'Syslogd';
20  }
21 
27  public function getVersion()
28  {
29  return 'dolibarr';
30  }
31 
37  public function getInfo()
38  {
39  global $langs;
40 
41  return $langs->trans('OnlyWindowsLOG_USER');
42  }
43 
49  public function isActive()
50  {
51  global $conf;
52 
53  // This function does not exists on some ISP (Ex: Free in France)
54  if (!function_exists('openlog')) {
55  return 0;
56  }
57 
58  return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_SYSLOG) ? 1 : 0; // Set SYSLOG_DISABLE_LOGHANDLER_SYSLOG to 1 to disable this loghandler
59  }
60 
66  public function configure()
67  {
68  global $langs;
69 
70  return array(
71  array(
72  'constant' => 'SYSLOG_FACILITY',
73  'name' => $langs->trans('SyslogFacility'),
74  'default' => 'LOG_USER'
75  )
76  );
77  }
78 
84  public function checkConfiguration()
85  {
86  global $conf, $langs;
87 
88  $errors = array();
89 
90  $facility = constant($conf->global->SYSLOG_FACILITY);
91  if ($facility) {
92  // Only LOG_USER supported on Windows
93  if (!empty($_SERVER["WINDIR"])) {
94  $facility = constant('LOG_USER');
95  }
96 
97  dol_syslog("admin/syslog: facility ".$facility);
98  } else {
99  $errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility);
100  }
101 
102  return $errors;
103  }
104 
111  public function export($content)
112  {
113  global $conf;
114 
115  if (!empty($conf->global->MAIN_SYSLOG_DISABLE_SYSLOG)) {
116  return; // Global option to disable output of this handler
117  }
118 
119  if (!empty($conf->global->SYSLOG_FACILITY)) { // Example LOG_USER
120  $facility = constant($conf->global->SYSLOG_FACILITY);
121  } else {
122  $facility = constant('LOG_USER');
123  }
124 
125  // (int) is required to avoid error parameter 3 expected to be long
126  openlog('dolibarr', LOG_PID | LOG_PERROR, (int) $facility);
127  syslog($content['level'], $content['message']);
128  closelog();
129  }
130 }
checkConfiguration()
Return if configuration is valid.
getInfo()
Content of the info tooltip.
Class to manage logging to syslog.
getName()
Return name of logger.
LogHandlerInterface.
configure()
Return array of configuration data.
isActive()
Is the module active ?
getVersion()
Version of the module (&#39;x.y.z&#39; or &#39;dolibarr&#39; or &#39;experimental&#39; or &#39;development&#39;)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
export($content)
Export the message.
Parent class for log handlers.
Definition: logHandler.php:23