00001 <?php
00025 $__log_udebug = false;
00059 class zLogger extends zCore{
00066 function error($msg, $title=null){
00067 $logBuffer =& $GLOBALS['____zigmoyd__Internal____Logg__Buffer____'];
00068 $logBuffer[] = array( 'type' => 'error',
00069 'title' => $title,
00070 'msg' => $msg,
00071 'timestamp' => time(),
00072 'time' => date(zDef::get('Z_LOG_STAMP_TIME')),
00073 'date' => date(zDef::get('Z_LOG_STAMP_DATE'))
00074 );
00075 zLogger::commit();
00076 }
00083 function debug($msg, $title=null, $udebug=false){
00084 $logBuffer =& $GLOBALS['____zigmoyd__Internal____Logg__Buffer____'];
00085 $logBuffer[] = array( 'type' => 'debug',
00086 'title' => $title,
00087 'msg' => $msg,
00088 'timestamp' => time(),
00089 'time' => date(zDef::get('Z_LOG_STAMP_TIME')),
00090 'date' => date(zDef::get('Z_LOG_STAMP_DATE'))
00091 );
00092 zLogger::commit($udebug);
00093 }
00098 function hr(){
00099 $logBuffer =& $GLOBALS['____zigmoyd__Internal____Logg__Buffer____'];
00100 $logBuffer[] = array( 'type' => 'debug',
00101 'title' => '==================',
00102 'msg' => '=============================================',
00103 'timestamp' => time(),
00104 'time' => date(zDef::get('Z_LOG_STAMP_TIME')),
00105 'date' => date(zDef::get('Z_LOG_STAMP_DATE'))
00106 );
00107 zLogger::commit();
00108 }
00113 function commit($udebug=false){
00114 isset($GLOBALS['____zigmoyd__Internal__Logg__Debug__File__Handle____']) ? $debugLogHandle =& $GLOBALS['____zigmoyd__Internal__Logg__Debug__File__Handle____'] : false;
00115 isset($GLOBALS['____zigmoyd__Internal__Logg__Error__File__Handle____']) ? $errorLogHandle =& $GLOBALS['____zigmoyd__Internal__Logg__Error__File__Handle____'] : false;
00116 $logBuffer =& $GLOBALS['____zigmoyd__Internal____Logg__Buffer____'];
00117 if(zDef::get('Z_LOG_LEVEL') != 0){
00118 switch(zDef::get('Z_LOG_MEDIA')){
00119 case 'file':
00120 if(zDef::get('Z_LOG_AUTOCOMMIT')){
00121 foreach($logBuffer as $logObj){
00122 $str = "\"$logObj[timestamp]\",\"$logObj[time]\",\"$logObj[date]\",\"$logObj[title]\",\"$logObj[msg]\"\n";
00123 if($logObj['type'] == 'error'){
00124
00125 if(fwrite($errorLogHandle, $str) === false){
00126 perror('<code>zigmoyd.log</code><br />failed to Log Error Message in error Log File');
00127 }
00128
00129
00130
00131
00132 }else{
00133 if(zDef::get('Z_LOG_LEVEL') == 2){
00134 if(fwrite($debugLogHandle, $str) === false){
00135 perror('<code>zigmoyd.log</code><br />failed to Log Debug Message');
00136 }
00137 }
00138 }
00139 }
00140 }
00141 break;
00142 case 'tty':
00143 if(PHP_OS == "WINNT")trigger_error('TTY Level Logging is Is Not aviliable under Windows', E_USER_NOTICE);
00144 foreach($logBuffer as $logObj){
00145
00146 if(($GLOBALS['__log_udebug'] && $udebug) || (!$GLOBALS['__log_udebug'])){
00147 if($logObj['type'] == 'error'){
00148 $str = "\033[35m$logObj[time]\033[0m \033[31m$logObj[title]\033[0m \t\t \033[5;30m\033[48m$logObj[msg]\033[0m";
00149 if(shell_exec("echo '$str' > ".zDef::get('Z_LOG_TTY'))){
00150 perror('<code>zigmoyd.log</code><br />failed to Log Error Message');
00151 }
00152 }else{
00153 if(zDef::get('Z_LOG_LEVEL') == 2){
00154 $str = "\033[35m$logObj[time]\033[0m \033[32m$logObj[title]\033[0m \t\t \033[34m$logObj[msg]\033[0m";
00155 if(shell_exec("echo '$str' > ".zDef::get('Z_LOG_TTY'))){
00156 perror('<code>zigmoyd.log</code><br />failed to Log Debug Message ');
00157 }
00158 }
00159 }
00160 }
00161 }
00162 $logBuffer = array();
00163 break;
00164 case 'socket':
00165 if(!isset($logHandle) || !is_object($logHandle))$logHandle =& $GLOBALS['____zigmoyd__Internal__Logg__socket__obj____'];
00166 if(($GLOBALS['__log_udebug'] && $udebug) || (!$GLOBALS['__log_udebug'])){
00167 foreach($logBuffer as $logObj){
00168 if($logObj['type'] == 'error'){
00169 if(is_object($logHandle))$logHandle->write($logObj);
00170 }else{
00171 if((zDef::get('Z_LOG_LEVEL') == 2)){
00172 if(is_object($logHandle))$logHandle->write($logObj);
00173 }
00174 }
00175 }
00176 }
00177 $logBuffer = array();
00178 break;
00179 default:
00180 perror('<code>zigmoyd.log</code><br />Invalid Log media (Z_LOG_MEDIA) "'.zDef::get('Z_LOG_MEDIA'));
00181 exit;
00182 }
00183 }
00184 }
00189 function release(){
00190 $debugLogHandle =& $GLOBALS['____zigmoyd__Internal__Logg__Debug__File__Handle____'];
00191 $errorLogHandle =& $GLOBALS['____zigmoyd__Internal__Logg__Error__File__Handle____'];
00192 if((zDef::get('Z_LOG_LEVEL') != 0) && !zDef::get('Z_LOG_AUTOCOMMIT')){
00193 zDef::set('Z_LOG_AUTOCOMMIT', true);
00194 zLogger::commit();
00195 zDef::set('Z_LOG_AUTOCOMMIT', false);
00196 is_resource($errorLogHandle) ? fclose($errorLogHandle) : false;
00197 is_resource($debugLogHandle) ? fclose($debugLogHandle) : false;
00198 }
00199 }
00206 function udebug($msg, $title=null){
00207 zLogger::debug($msg, $title, true);
00208 }
00212 function udebugOn(){
00213 $GLOBALS['__log_udebug'] = true;
00214 }
00218 function udebugOff(){
00219 $GLOBALS['__log_udebug'] = false;
00220 }
00221 }
00222 if(!isset($__Z__isRouter) || !$__Z__isRouter){
00223 zLogger::debug("Initializing Logging system (Serving Application) $projectName.$controllerName/$methodName/".implode('/', $args), 'logger.init');
00224 }else{
00225 $prjName = ($prjName = url_segment(0)) ? $prjName : ' NULL ';
00226 $contentType = ($contentType = url_segment(0)) ? $contentType : ' NULL ';
00227 $filePath = ($filePath = url_segment(0)) ? $filePath : ' NULL ';
00228 if(!zDef::get('Z_LOG_UDEBUG'))zLogger::debug("Initializing Logging system (Serving Shared Content) Project: $prjName Media: $contentType File: $contentType", 'logger.init');
00229 }
00230 register_shutdown_function(array('zLogger', 'release'));
00232 ?>