1 <?php
2
3 4 5 6 7 8 9
10 class MagratheaLogger {
11
12 13 14 15 16 17
18 public static function Log($logThis, $logFile=null){
19 if( is_a($logThis, "MagratheaConfigException") ){
20 echo "==[config not properly set!]==";
21 return;
22 }
23 $path = MagratheaConfig::Instance()->GetConfigFromDefault("site_path")."/../logs/";
24 if(empty($logFile)) $logFile = "log_".@date("Ym").".txt";
25 $date = @date("Y-m-d h:i:s");
26 $line = "[".$date."] = ".$logThis."\n\n";
27 $file = $path.$logFile;
28 if(!is_writable($path)){
29 $message = "error trying to save file at [".$path."] - confirm permission for writing";
30 throw new Exception($message);
31 return;
32 }
33 file_put_contents($file, $line, FILE_APPEND | LOCK_EX);
34 }
35 36 37 38 39 40
41 public static function LogError($error, $filename=null){
42 $path = MagratheaConfig::Instance()->GetConfigFromDefault("site_path")."/../logs/";
43 if(empty($filename)) $filename = "log_error";
44 $date = @date("Y-m-d_his");
45 $filename .= $date.".txt";
46 $line = "[".$date."] = ".$logThis."\n\n";
47 $file = $path.$filename;
48 if(!is_writable($path)){
49 throw new Exception("error trying to save file at [".$path."] - confirm permission for writing");
50 return;
51 }
52 file_put_contents($file, $line, FILE_APPEND | LOCK_EX);
53 }
54 }
55
56 ?>