-
Notifications
You must be signed in to change notification settings - Fork 123
/
DqLog.php
54 lines (49 loc) · 1.76 KB
/
DqLog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
class DqLog{
const LOG_TYPE_NORMAL=1;
const LOG_TYPE_EXCEPTION=2;
//通知日志
const LOG_TYPE_NOTIFY_START=3;
const LOG_TYPE_NOTIFY_FAIL=4;
const LOG_TYPE_NOTIFY_SUCC=5;
const LOG_TYPE_REQUEST=6; //记录所有的请求日志
public static function writeLog($str,$flag=self::LOG_TYPE_NORMAL){
$p_name='';
if(php_sapi_name()=='cli'){
$p_name = cli_get_process_title();
}
$str = "[" . date('Y-m-d H:i:s') . "]p_name=".$p_name.' '. $str;
$dir = self::getLogDir();
$seg=date('Ymd');
switch ($flag) {
case self::LOG_TYPE_EXCEPTION:
$fileName = $dir . '/err_' . $seg . '.txt';
file_put_contents($fileName, $str . "\n", FILE_APPEND);
break;
case self::LOG_TYPE_NORMAL:
$fileName = $dir . '/notice_' . $seg . '.txt';
file_put_contents($fileName, $str . "\n", FILE_APPEND);
break;
case self::LOG_TYPE_NOTIFY_START:
case self::LOG_TYPE_NOTIFY_SUCC:
case self::LOG_TYPE_NOTIFY_FAIL:
$fileName = $dir . '/notify_' . $seg . '.txt';
file_put_contents($fileName, $str . "\n", FILE_APPEND);
break;
case self::LOG_TYPE_REQUEST:
$fileName = $dir . '/request_' . $seg . '.txt';
file_put_contents($fileName, $str . "\n", FILE_APPEND);
break;
}
}
public static function getLogDir(){
$dir = dirname(__FILE__) . '/logs/';
if(!empty(DqConf::$logPath)){
$dir = rtrim(DqConf::$logPath,'/').'/';
}
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
return $dir;
}
}