dolibarr  13.0.2
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')) return 0;
55 
56  return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_SYSLOG) ? 1 : 0; // Set SYSLOG_DISABLE_LOGHANDLER_SYSLOG to 1 to disable this loghandler
57  }
58 
64  public function configure()
65  {
66  global $langs;
67 
68  return array(
69  array(
70  'constant' => 'SYSLOG_FACILITY',
71  'name' => $langs->trans('SyslogFacility'),
72  'default' => 'LOG_USER'
73  )
74  );
75  }
76 
82  public function checkConfiguration()
83  {
84  global $conf, $langs;
85 
86  $errors = array();
87 
88  $facility = constant($conf->global->SYSLOG_FACILITY);
89  if ($facility)
90  {
91  // Only LOG_USER supported on Windows
92  if (!empty($_SERVER["WINDIR"])) $facility = constant('LOG_USER');
93 
94  dol_syslog("admin/syslog: facility ".$facility);
95  } else {
96  $errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility);
97  }
98 
99  return $errors;
100  }
101 
108  public function export($content)
109  {
110  global $conf;
111 
112  if (!empty($conf->global->MAIN_SYSLOG_DISABLE_SYSLOG)) return; // Global option to disable output of this handler
113 
114  if (!empty($conf->global->SYSLOG_FACILITY)) // Example LOG_USER
115  {
116  $facility = constant($conf->global->SYSLOG_FACILITY);
117  } else $facility = constant('LOG_USER');
118 
119  // (int) is required to avoid error parameter 3 expected to be long
120  openlog('dolibarr', LOG_PID | LOG_PERROR, (int) $facility);
121  syslog($content['level'], $content['message']);
122  closelog();
123  }
124 }
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.
print $_SERVER["PHP_SELF"]
Edit parameters.
export($content)
Export the message.
Parent class for log handlers.
Definition: logHandler.php:23