dolibarr  9.0.0
mod_syslog_firephp.php
1 <?php
2 /* Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2015 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 require_once DOL_DOCUMENT_ROOT.'/core/modules/syslog/logHandler.php';
20 
25 {
26  public $code = 'firephp';
27  private static $firephp_include_path = '/includes/firephp/firephp-core/lib/';
28  private static $firephp_class_path = 'FirePHPCore/FirePHP.class.php';
29 
35  public function getName()
36  {
37  return 'FirePHP';
38  }
39 
45  public function getVersion()
46  {
47  return 'dolibarr';
48  }
49 
55  public function getInfo()
56  {
57  global $langs;
58 
59  return ($this->isActive() == 1)?'':$langs->trans('ClassNotFoundIntoPathWarning', self::$firephp_class_path);
60  }
61 
67  public function isActive()
68  {
69  global $conf;
70  try
71  {
72  if (empty($conf->global->SYSLOG_FIREPHP_INCLUDEPATH)) {
73  $conf->global->SYSLOG_FIREPHP_INCLUDEPATH = DOL_DOCUMENT_ROOT . self::$firephp_include_path;
74  }
75  set_include_path($conf->global->SYSLOG_FIREPHP_INCLUDEPATH);
76  $res = @include_once self::$firephp_class_path;
77  restore_include_path();
78  if ($res) {
79  return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_FIREPHP)?1:0; // Set SYSLOG_DISABLE_LOGHANDLER_FIREPHP to 1 to disable this loghandler
80  } else {
81  return 0;
82  }
83  }
84  catch(Exception $e)
85  {
86  print '<!-- FirePHP not available into PHP -->'."\n";
87  }
88 
89  return -1;
90  }
91 
97  public function configure()
98  {
99  global $langs;
100 
101  return array(
102  array(
103  'name' => $langs->trans('IncludePath', 'SYSLOG_FIREPHP_INCLUDEPATH'),
104  'constant' => 'SYSLOG_FIREPHP_INCLUDEPATH',
105  'default' => DOL_DOCUMENT_ROOT . self::$firephp_include_path,
106  'attr' => 'size="60"',
107  'example' => '/usr/share/php, ' . DOL_DOCUMENT_ROOT . self::$firephp_include_path
108  )
109  );
110  }
111 
117  public function checkConfiguration()
118  {
119  global $conf, $langs;
120 
121  $errors = array();
122 
123  if (!file_exists($conf->global->SYSLOG_FIREPHP_INCLUDEPATH . self::$firephp_class_path))
124  {
125  $conf->global->MAIN_SYSLOG_DISABLE_FIREPHP = 1; // avoid infinite loop
126  if (is_object($langs)) // $langs may not be defined yet.
127  {
128  $errors[] = $langs->trans("ErrorFailedToOpenFile", self::$firephp_class_path);
129  }
130  else
131  {
132  $errors[] = "ErrorFailedToOpenFile " . self::$firephp_class_path;
133  }
134  }
135 
136  return $errors;
137  }
138 
145  public function export($content)
146  {
147  global $conf;
148 
149  if (! empty($conf->global->MAIN_SYSLOG_DISABLE_FIREPHP)) return; // Global option to disable output of this handler
150 
151  //We check the configuration to avoid showing PHP warnings
152  if (count($this->checkConfiguration())) return false;
153 
154  try
155  {
156  // Warning FirePHPCore must be into PHP include path. It is not possible to use into require_once a constant from
157  // database or config file because we must be able to log data before database or config file read.
158  $oldinclude=get_include_path();
159  set_include_path($conf->global->SYSLOG_FIREPHP_INCLUDEPATH);
160  include_once self::$firephp_class_path;
161  set_include_path($oldinclude);
162  ob_start(); // To be sure headers are not flushed until all page is completely processed
163  $firephp = FirePHP::getInstance(true);
164  if ($content['level'] == LOG_ERR) $firephp->error($content['message']);
165  elseif ($content['level'] == LOG_WARNING) $firephp->warn($content['message']);
166  elseif ($content['level'] == LOG_INFO) $firephp->log($content['message']);
167  else $firephp->log($content['message']);
168  }
169  catch (Exception $e)
170  {
171  // Do not use dol_syslog here to avoid infinite loop
172  return false;
173  }
174  }
175 }
isActive()
Is the module active ?
print
Draft customers invoices.
Definition: index.php:91
checkConfiguration()
Return if configuration is valid.
getName()
Return name of logger.
Class to manage logging to a FirePHP.
LogHandlerInterface.
configure()
Return array of configuration data.
export($content)
Output log content.
getInfo()
Content of the info tooltip.
Parent class for log handlers.
Definition: logHandler.php:23
getVersion()
Version of the module (&#39;x.y.z&#39; or &#39;dolibarr&#39; or &#39;experimental&#39; or &#39;development&#39;)