-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.php
64 lines (53 loc) · 1.24 KB
/
log.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
55
56
57
58
59
60
61
62
63
<?php
/*
*/
date_default_timezone_set('Etc/GMT-8');
class MyLog
{
const LOG_LVL_DBG = 0;
const LOG_LVL_INF = 1;
const LOG_LVL_WRN = 2;
const LOG_LVL_CRT = 3;
private static $_logFile = null;
private static $_logLvl = self::LOG_LVL_DBG;
private static $_logTxt = array(
self::LOG_LVL_DBG => "DBG",
self::LOG_LVL_INF => "INF",
self::LOG_LVL_WRN => "WRN",
self::LOG_LVL_CRT => "CRT",
);
private static function logInfo($lvl, $str)
{
if (self::$_logFile == null)
{
self::$_logFile = fopen('log.txt', 'a');
if (self::$_logFile == null)
{
return;
}
}
if ($lvl >= self::$_logLvl)
{
$now = date("Y/m/d G:i:s");
$logTxt = self::$_logTxt[$lvl];
fwrite(self::$_logFile, "[$now][$logTxt]\t$str\r\n");
}
}
public static function dbg($str)
{
self::logInfo(self::LOG_LVL_DBG, $str);
}
public static function inf($str)
{
self::logInfo(self::LOG_LVL_INF, $str);
}
public static function wrn($str)
{
self::logInfo(self::LOG_LVL_WRN, $str);
}
public static function crt($str)
{
self::logInfo(self::LOG_LVL_CRT, $str);
}
}
?>