dolibarr  7.0.0-beta
mod_syslog_syslog.php
1 <?php
2 
3 require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php';
4 
9 {
10  var $code = 'syslog';
11 
17  public function getName()
18  {
19  return 'Syslog';
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  }
96  else
97  {
98  $errors[] = $langs->trans("ErrorUnknownSyslogConstant", $facility);
99  }
100 
101  return $errors;
102  }
103 
110  public function export($content)
111  {
112  global $conf;
113 
114  if (! empty($conf->global->MAIN_SYSLOG_DISABLE_SYSLOG)) return; // Global option to disable output of this handler
115 
116  if (! empty($conf->global->SYSLOG_FACILITY)) // Example LOG_USER
117  {
118  $facility = constant($conf->global->SYSLOG_FACILITY);
119  }
120  else $facility = constant('LOG_USER');
121 
122  // (int) is required to avoid error parameter 3 expected to be long
123  openlog('dolibarr', LOG_PID | LOG_PERROR, (int) $facility);
124  syslog($content['level'], $content['message']);
125  closelog();
126  }
127 }
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
isActive()
Is the module active ?
getVersion()
Version of the module ('x.y.z' or 'dolibarr' or 'experimental' or 'development')
export($content)
Export the message.
Parent class for log handlers.
Definition: logHandler.php:23