MkFramework
 All Data Structures Functions
plugin_log.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
23 class plugin_log{
24 
25  private $bInfo;
26  private $bWarning;
27  private $bError;
28  private $bAppli;
29 
34  public function __construct(){
35  $this->setApplication(true);
36  $this->setInformation(true);
37  $this->setWarning(true);
38  $this->setError(true);
39 
40  }
46  public function setApplication($bActif){
47  $this->bAppli=$bActif;
48  }
54  public function setInformation($bActif){
55  $this->bInfo=$bActif;
56  }
62  public function setWarning($bActif){
63  $this->bWarning=$bActif;
64  }
70  public function setError($bActif){
71  $this->bError=$bActif;
72  }
73 
79  public function log($sMessage){
80  if(!$this->bAppli){ return null;}
81  $this->writefile('log;'.$sMessage);
82  return true;
83  }
89  public function error($sMessage){
90  if(!$this->bError){ return null;}
91  $this->writefile('ERROR;'.$sMessage);
92  return true;
93  }
99  public function warning($sMessage){
100  if(!$this->bWarning){ return null;}
101  $this->writefile('Warning;'.$sMessage);
102  return true;
103  }
109  public function info($sMessage){
110  if(!$this->bInfo){ return null;}
111  $this->writefile('info;'.$sMessage);
112  return true;
113  }
114 
115  private function writefile($sMessage){
116 
117  $sMessage= preg_replace('/\s+/',' ',$sMessage);
118 
119  $oFileLog=new _file(_root::getConfigVar('path.log','data/log/').date('Y-m-d').'_log.csv');
120  if($oFileLog->exist()){ $oFileLog->load();}
121 
122  $oFileLog->addContent(date('Y-m-d').';'.date('H:i:s').';'.$sMessage."\n");
123 
124  try{
125  $oFileLog->save();
126  }catch(Exception $e){
127  throw new Exception (
128  'Probleme lors de l\'ecriture du log'."\n"
129  .'note:verifier les droits du repertoire '._root::getConfigVar('path.log','data/log')."\n"
130  .'Exception: '.$e->getMessage());
131  }
132 
133  $oFileLog->clean();
134  }
135 
136 }
error($sMessage)
Definition: plugin_log.php:89
setWarning($bActif)
Definition: plugin_log.php:62
setError($bActif)
Definition: plugin_log.php:70
setApplication($bActif)
Definition: plugin_log.php:46
static getConfigVar($sCatAndVar, $uDefaut=null)
Definition: class_root.php:654
setInformation($bActif)
Definition: plugin_log.php:54
warning($sMessage)
Definition: plugin_log.php:99
info($sMessage)
Definition: plugin_log.php:109
log($sMessage)
Definition: plugin_log.php:79