dolibarr  7.0.0-beta
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  if (is_object($langs)) // $langs may not be defined yet.
125  {
126  $errors[] = $langs->trans("ErrorFailedToOpenFile", 'ChromePhp.class.php or ChromePhp.php');
127  }
128  else
129  {
130  $errors[] = "ErrorFailedToOpenFile ChromePhp.class.php or ChromePhp.php";
131  }
132  }
133 
134  return $errors;
135  }
136 
143  public function export($content)
144  {
145  global $conf;
146 
147  if (! empty($conf->global->MAIN_SYSLOG_DISABLE_CHROMEPHP)) return; // Global option to disable output of this handler
148 
149  //We check the configuration to avoid showing PHP warnings
150  if (count($this->checkConfiguration()) > 0) return false;
151 
152  try
153  {
154  // Warning ChromePHP must be into PHP include path. It is not possible to use into require_once() a constant from
155  // database or config file because we must be able to log data before database or config file read.
156  $oldinclude=get_include_path();
157  set_include_path($conf->global->SYSLOG_CHROMEPHP_INCLUDEPATH);
158  $res = @include_once('ChromePhp.php');
159  if (! $res) $res=@include_once('ChromePhp.class.php');
160  set_include_path($oldinclude);
161 
162  ob_start(); // To be sure headers are not flushed until all page is completely processed
163  if ($content['level'] == LOG_ERR) ChromePhp::error($content['message']);
164  elseif ($content['level'] == LOG_WARNING) ChromePhp::warn($content['message']);
165  elseif ($content['level'] == LOG_INFO) ChromePhp::log($content['message']);
166  else ChromePhp::log($content['message']);
167  }
168  catch (Exception $e)
169  {
170  // Do not use dol_syslog here to avoid infinite loop
171  }
172  }
173 }
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 ('x.y.z' or 'dolibarr' or 'experimental' or 'development')
configure()
Return array of configuration data.
print
Draft customers invoices.
Definition: index.php:91
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