[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+*********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *************************************************************************************/ 10 11 /** Classes to avoid logging */ 12 13 class LoggerManager { 14 static function getlogger($name = 'ROOT') { 15 $configinfo = LoggerPropertyConfigurator::getInstance()->getConfigInfo($name); 16 return new Logger($name, $configinfo); 17 } 18 } 19 20 /** 21 * Core logging class. 22 */ 23 class Logger { 24 private $name = false; 25 private $appender = false; 26 private $configinfo = false; 27 28 /** 29 * Writing log file information could cost in-terms of performance. 30 * Enable logging based on the levels here explicitly 31 */ 32 private $enableLogLevel = array( 33 'ERROR' => false, 34 'FATAL' => false, 35 'INFO' => false, 36 'WARN' => false, 37 'DEBUG' => false, 38 ); 39 40 function __construct($name, $configinfo = false) { 41 $this->name = $name; 42 $this->configinfo = $configinfo; 43 44 /** For migration log-level we need debug turned-on */ 45 if(strtoupper($name) == 'MIGRATION') { 46 $this->enableLogLevel['DEBUG'] = true; 47 } 48 49 } 50 51 function emit($level, $message) { 52 if(!$this->appender) { 53 $filename = 'logs/vtigercrm.log'; 54 if($this->configinfo && isset($this->configinfo['appender']['File'])) { 55 $filename = $this->configinfo['appender']['File']; 56 } 57 $this->appender = new LoggerAppenderFile($filename, 0777); 58 } 59 $mypid = @getmypid(); 60 61 $this->appender->emit("$level [$mypid] $this->name - ", $message); 62 } 63 64 function info($message) { 65 if($this->isLevelEnabled('INFO')) { 66 $this->emit('INFO', $message); 67 } 68 } 69 70 function debug($message) { 71 if($this->isDebugEnabled()) { 72 $this->emit('DEBUG', $message); 73 } 74 } 75 76 function warn($message) { 77 if($this->isLevelEnabled('WARN')) { 78 $this->emit('WARN', $message); 79 } 80 } 81 82 function fatal($message) { 83 if($this->isLevelEnabled('FATAL')) { 84 $this->emit('FATAL', $message); 85 } 86 } 87 88 function error($message) { 89 if($this->isLevelEnabled('ERROR')) { 90 $this->emit('ERROR', $message); 91 } 92 } 93 94 function isLevelEnabled($level) { 95 if($this->enableLogLevel[$level] && $this->configinfo) { 96 return (strtoupper($this->configinfo['level']) == $level); 97 } 98 return false; 99 } 100 101 function isDebugEnabled() { 102 return $this->isLevelEnabled('DEBUG'); 103 } 104 } 105 106 /** 107 * Log message appender to file. 108 */ 109 class LoggerAppenderFile { 110 111 private $filename; 112 private $chmod; 113 114 function __construct($filename, $chmod = 0222) { 115 $this->filename = $filename; 116 $this->chmod = $chmod; 117 } 118 119 function emit($prefix, $message) { 120 if($this->chmod != 0777 && file_exists($this->filename)) { 121 if(is_readable($this->filename)) { 122 @chmod($this->filename, $this->chmod); 123 } 124 } 125 $fh = @fopen($this->filename, 'a'); 126 if($fh) { 127 @fwrite($fh, date('m/d/Y H:i:s') . " $prefix $message\n"); 128 @fclose($fh); 129 } 130 } 131 132 } 133 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |