dolibarr  9.0.0
mod_syslog_chromephp.php
1 <?php
2 
3 require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php';
4 
9 {
10  var $code = 'chromephp';
11 
17  public function getName()
18  {
19  return 'ChromePHP';
20  }
21 
27  public function getVersion()
28  {
29  return 'dolibarr';
30  }
31 
37  public function getInfo()
38  {
39  return '';
40  }
41 
47  public function getWarning()
48  {
49  global $langs;
50 
51  return ($this->isActive() == 1)?'':$langs->trans('ClassNotFoundIntoPathWarning','ChromePhp.class.php');
52  }
53 
59  public function isActive()
60  {
61  global $conf;
62  try
63  {
64  if (empty($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH)) {
65  $conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH = DOL_DOCUMENT_ROOT . '/includes/ccampbell/chromephp/';
66  }
67  set_include_path($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH);
68 
69  $res = @include_once 'ChromePhp.php';
70  if (! $res) $res=@include_once 'ChromePhp.class.php';
71 
72  restore_include_path();
73 
74  if ($res)
75  {
76  return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_CHROMEPHP)?1:0; // Set SYSLOG_DISABLE_LOGHANDLER_CHROMEPHP to 1 to disable this loghandler
77  }
78  else
79  {
80  return 0;
81  }
82  }
83  catch(Exception $e)
84  {
85  print '<!-- ChromePHP not available into PHP -->'."\n";
86  }
87 
88  return -1;
89  }
90 
96  public function configure()
97  {
98  global $langs;
99 
100  return array(
101  array(
102  'name' => $langs->trans('IncludePath','SYSLOG_CHROMEPHP_INCLUDEPATH'),
103  'constant' => 'SYSLOG_CHROMEPHP_INCLUDEPATH',
104  'default' => DOL_DOCUMENT_ROOT . '/includes/ccampbell/chromephp/',
105  'attr' => 'size="60"',
106  'example' =>'/usr/share/php, '.DOL_DOCUMENT_ROOT . '/includes/ccampbell/chromephp/'
107  )
108  );
109  }
110 
116  public function checkConfiguration()
117  {
118  global $langs,$conf;
119 
120  $errors = array();
121 
122  if (! file_exists($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH.'/ChromePhp.php') && ! file_exists($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH.'/ChromePhp.class.php'))
123  {
124  $conf->global->MAIN_SYSLOG_DISABLE_CHROMEPHP = 1; // avoid infinite loop
125  if (is_object($langs)) // $langs may not be defined yet.
126  {
127  $errors[] = $langs->trans("ErrorFailedToOpenFile", 'ChromePhp.class.php or ChromePhp.php');
128  }
129  else
130  {
131  $errors[] = "ErrorFailedToOpenFile ChromePhp.class.php or ChromePhp.php";
132  }
133  }
134 
135  return $errors;
136  }
137 
144  public function export($content)
145  {
146  global $conf;
147 
148  if (! empty($conf->global->MAIN_SYSLOG_DISABLE_CHROMEPHP)) return; // Global option to disable output of this handler
149 
150  //We check the configuration to avoid showing PHP warnings
151  if (count($this->checkConfiguration()) > 0) return false;
152 
153  try
154  {
155  // Warning ChromePHP must be into PHP include path. It is not possible to use into require_once a constant from
156  // database or config file because we must be able to log data before database or config file read.
157  $oldinclude=get_include_path();
158  set_include_path($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH);
159  $res = @include_once 'ChromePhp.php';
160  if (! $res) $res=@include_once 'ChromePhp.class.php';
161  set_include_path($oldinclude);
162 
163  ob_start(); // To be sure headers are not flushed until all page is completely processed
164  if ($content['level'] == LOG_ERR) ChromePhp::error($content['message']);
165  elseif ($content['level'] == LOG_WARNING) ChromePhp::warn($content['message']);
166  elseif ($content['level'] == LOG_INFO) ChromePhp::log($content['message']);
167  else ChromePhp::log($content['message']);
168  }
169  catch (Exception $e)
170  {
171  // Do not use dol_syslog here to avoid infinite loop
172  }
173  }
174 }
print
Draft customers invoices.
Definition: index.php:91
export($content)
Output log content.
getInfo()
Content of the info tooltip.
checkConfiguration()
Return if configuration is valid.
LogHandlerInterface.
Class to manage logging to ChromPHP.
getVersion()
Version of the module (&#39;x.y.z&#39; or &#39;dolibarr&#39; or &#39;experimental&#39; or &#39;development&#39;)
configure()
Return array of configuration data.
getWarning()
Return warning if something is wrong with logger.
getName()
Return name of logger.
isActive()
Is the module active ?
Parent class for log handlers.
Definition: logHandler.php:23