dolibarr  7.0.0-beta
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  $errors[] = $langs->trans("ErrorFailedToOpenFile", self::$firephp_class_path);
126  }
127 
128  return $errors;
129  }
130 
137  public function export($content)
138  {
139  global $conf;
140 
141  if (! empty($conf->global->MAIN_SYSLOG_DISABLE_FIREPHP)) return; // Global option to disable output of this handler
142 
143  //We check the configuration to avoid showing PHP warnings
144  if (count($this->checkConfiguration())) return false;
145 
146  try
147  {
148  // Warning FirePHPCore must be into PHP include path. It is not possible to use into require_once() a constant from
149  // database or config file because we must be able to log data before database or config file read.
150  $oldinclude=get_include_path();
151  set_include_path($conf->global->SYSLOG_FIREPHP_INCLUDEPATH);
152  include_once self::$firephp_class_path;
153  set_include_path($oldinclude);
154  ob_start(); // To be sure headers are not flushed until all page is completely processed
155  $firephp = FirePHP::getInstance(true);
156  if ($content['level'] == LOG_ERR) $firephp->error($content['message']);
157  elseif ($content['level'] == LOG_WARNING) $firephp->warn($content['message']);
158  elseif ($content['level'] == LOG_INFO) $firephp->log($content['message']);
159  else $firephp->log($content['message']);
160  }
161  catch (Exception $e)
162  {
163  // Do not use dol_syslog here to avoid infinite loop
164  return false;
165  }
166  }
167 }
isActive()
Is the module active ?
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.
print
Draft customers invoices.
Definition: index.php:91
getInfo()
Content of the info tooltip.
Parent class for log handlers.
Definition: logHandler.php:23
getVersion()
Version of the module ('x.y.z' or 'dolibarr' or 'experimental' or 'development')