forked from chenlinzhong/php-delayqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DqLog.php
50 lines (45 loc) · 1.66 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
<?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){
$str = "[" . date('Y-m-d H:i:s') . "]PID=". DqMain::$pid.' '. $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;
}
}