dolibarr  16.0.5
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 }
LogHandler
Parent class for log handlers.
Definition: logHandler.php:23
mod_syslog_syslog\checkConfiguration
checkConfiguration()
Return if configuration is valid.
Definition: mod_syslog_syslog.php:84
mod_syslog_syslog\getVersion
getVersion()
Version of the module ('x.y.z' or 'dolibarr' or 'experimental' or 'development')
Definition: mod_syslog_syslog.php:27
mod_syslog_syslog\getName
getName()
Return name of logger.
Definition: mod_syslog_syslog.php:17
LogHandlerInterface
LogHandlerInterface.
Definition: logHandlerInterface.php:27
mod_syslog_syslog\export
export($content)
Export the message.
Definition: mod_syslog_syslog.php:111
mod_syslog_syslog\isActive
isActive()
Is the module active ?
Definition: mod_syslog_syslog.php:49
mod_syslog_syslog
Class to manage logging to syslog.
Definition: mod_syslog_syslog.php:8
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
mod_syslog_syslog\getInfo
getInfo()
Content of the info tooltip.
Definition: mod_syslog_syslog.php:37
mod_syslog_syslog\configure
configure()
Return array of configuration data.
Definition: mod_syslog_syslog.php:66