Passed
Push — v6 ( ba732b...0da0a0 )
by 光春
03:16
created

Logger::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
1
<?php
2
require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
3
class Logger{
4
	function info($msg){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
5
		$this->log("INFO",$msg);
6
	}
7
	function error($msg){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8
		$this->log("ERROR",$msg);
9
	}
10
	function warn($msg){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
		$this->log("WARN",$msg);
12
	}
13
	function debug($msg){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14
		$this->log("DEBUG",$msg);
15
	}
16
	private function log($level,$msg){
17
		$date = gmdate('D, d M Y H:i:s \G\M\T');
18
		$log = $date." ".$level."\r\n".$msg."\r\n";
19
		if(defined('KS3_API_LOG_PATH') ){
20
			$log_path = KS3_API_LOG_PATH;
21
			if(empty($log_path)){
0 ignored issues
show
introduced by
The condition empty($log_path) is always true.
Loading history...
22
				$log_path = KS3_API_PATH.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR;
23
			}
24
		}else{
25
			$log_path = KS3_API_PATH.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR;
26
		}
27
		
28
		//检测日志目录是否存在
29
		if(!file_exists($log_path)){
30
			mkdir($log_path);
31
		}
32
33
		$log_name = $log_path.'ks3_php_sdk_'.date('Y-m-d').'.log';
34
35
		if(KS3_API_DISPLAY_LOG){
36
			echo $log;
37
		}
38
		
39
		if(KS3_API_LOG){
40
			if(!error_log($log,3,$log_name)){
41
				throw new Ks3ClientException("write to log file error");
42
			}
43
		}
44
	}
45
}
46
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...