File indexing completed on 2024-12-22 05:33:23

0001 <?php
0002 /*
0003  *   TRT GFX 3.0.1 (beta build) BackToSlash
0004  * 
0005  *   support: happy.snizzo@gmail.com
0006  *   website: http://trt-gfx.googlecode.com
0007  *   credits: Claudio Desideri
0008  *   
0009  *   This software is released under the MIT License.
0010  *   http://opensource.org/licenses/mit-license.php
0011  */ 
0012 
0013 /*
0014  * Catching and management error class.
0015  * 
0016  * Now static class.
0017  */
0018 
0019 class ELog {
0020   /*
0021    * mode:
0022    *  0 - print log on screen in plain text
0023    *  1 - print log on screen with some html
0024    *  2 - print log on text file ($name.log)
0025    */
0026   public static $errormode = 0;
0027   public static $error_file = "error.log";
0028   public static $warning_file = "warning.log";
0029   public static $preserve_errors = false;
0030   public static $preserve_warnings = false;
0031   public static $mode = 'nice';
0032   
0033   public static function error($r){
0034     ELog::$mode = EConfig::$data['generic']['errormode'];
0035     
0036     switch (ELog::$mode){
0037       case 'normal':
0038         echo "GFX ERROR: $r<br><pre> BACKTRACE: ";
0039         debug_print_backtrace();
0040         echo "</pre>";
0041         die();
0042       case 'formatted':
0043         die("<div style=\"border:3px red solid;-moz-border-radius:10px;background-color:#CECECE;padding:7px;margin:auto;margin-top:7px;margin-bottom:7px;font-size:100%; width:300px;\">
0044         <center><big><big><b>GFX ERROR:</b></big></big></center>
0045         <i>$r</i></div>");
0046       case 'file':
0047         $stream = fopen(ELog::$error_file, 'a+');
0048         fwrite($stream, "GFX ERROR: $r\n\n");
0049         fclose($stream);
0050       case 'suppressed':
0051         //ignore error
0052         break;
0053     }
0054   }
0055   
0056   public static function warning($r){
0057     ELog::$mode = EConfig::$data['generic']['errormode'];
0058     
0059     switch (ELog::$mode){
0060       case 'normal':
0061         echo "GFX WARNING: $r<br>";
0062         break;
0063       case 'formatted':
0064         echo "<p style=\"color:#CDD500;font-size:20px;\">GFX WARNING:</p>
0065           <p style=\"color:#D58600;font-size:15px;font-style:italic;\">$r</p>";
0066       case 'file':
0067         $stream = fopen(ELog::$warning_file, 'a+');
0068         fwrite($stream, "GFX WARNING: $r\n\n");
0069         fclose($stream);
0070       case 'suppressed':
0071         //ignore error
0072         break;
0073     }
0074   }
0075   
0076   public static function d($s){
0077     echo "<pre>$s</pre>";
0078   }
0079   
0080   //TODO: implement print of arrays indepenent from var_dump
0081   
0082   public static function pd($q){
0083     echo "<pre>";
0084     var_dump($q);
0085     echo "</pre>";
0086   }
0087   
0088   public static function clear_log(){
0089     if(file_exists(ELog::$error_file) and ELog::$preserve_errors == false){
0090       unlink(ELog::$error_file);
0091     }
0092     if(file_exists(ELog::$warning_file) and ELog::$preserve_warnings == false){
0093       unlink(ELog::$warning_file);
0094     }
0095   }
0096   
0097 }
0098 
0099 ?>