-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDbg.ts
More file actions
83 lines (73 loc) · 2.45 KB
/
Dbg.ts
File metadata and controls
83 lines (73 loc) · 2.45 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
namespace KBEngine
{
export const enum DEBUGLEVEL
{
DEBUG = 0,
INFO,
WARNING,
ERROR,
NOLOG, // 放在最后面,使用这个时表示不输出任何日志(!!!慎用!!!)
}
export class Dbg
{
public static debugLevel:DEBUGLEVEL = DEBUGLEVEL.DEBUG;
static getHead(): string
{
let now: Date = new Date();
return "[" + now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " " + now.getHours()
+ ":" + now.getMinutes() + ":" + now.getSeconds() + " " + now.getMilliseconds() + "] ";
}
static DEBUG_MSG(msg: string, ...params: any[]): void
{
if(DEBUGLEVEL.DEBUG >= this.debugLevel)
{
params.unshift(this.getHead(), msg);
console.debug.apply(this, params);
}
}
static INFO_MSG(msg: string, ...params: any[]): void
{
if(DEBUGLEVEL.INFO >= this.debugLevel)
{
params.unshift(this.getHead(), msg);
console.info.apply(this, params);
}
}
static WARNING_MSG(msg: string, ...params: any[]): void
{
if(DEBUGLEVEL.WARNING >= this.debugLevel)
{
params.unshift(this.getHead(), msg);
console.warn.apply(this, params);
}
}
static ERROR_MSG(msg: string, ...params: any[]): void
{
if(DEBUGLEVEL.ERROR >= this.debugLevel)
{
params.unshift(this.getHead(), msg);
console.error.apply(this, params);
}
}
static ASSERT(condition?: boolean, message?: string, ...data: any[]): void
{
// 使用抛出异常的方式来实现类似断言功能
if(!condition)
{
throw(new Error(message));
}
// note:微信小游戏平台不支持,手册中提到的CC_WECHATGAME未定义,无法区分是否微信小游戏平台,
// console.assert(condition, message, ...data);
// 一些平台如小程序上可能没有assert
// if(console.assert == undefined)
// {
// console.assert = function(bRet, s)
// {
// if(!(bRet)) {
// ERROR_MSG(s);
// }
// }
// }
}
}
}