-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLogger.aardio
69 lines (63 loc) · 2.35 KB
/
Logger.aardio
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
//Logger 日志类
namespace log4j
class Logger {
ctor(loggerCategory = 'default' /*日志类别*/,config/*默认配置*/){
import log4j.appenders
this.config =config || log4j.config
this.loggerCategory = loggerCategory
this.callLevel = 'DEBUG'
this.defaultLevel = this.config.level
this.levels = log4j.levels
};
console = function(...){
for(k,categorie in this.config.categories){
var categorieLevel = categorie.level || this.defaultLevel
var callLevel = this.getLevelNumber(this.callLevel);
var theLevel = this.getLevelNumber(categorieLevel)
if (callLevel < theLevel) continue
//..console.log('this.callLevel',this.callLevel,categorieLevel,callLevel,theLevel,callLevel < theLevel)
for(key,appenderKey in categorie.appenders){
//..console.dump(appenderKey)
var appender = this.config.appenders[appenderKey]
var loggingEvent = {
loggerCategory = this.loggerCategory;
level = this.callLevel;
type = appender.type;
fileName = appender.fileName;
layouts = appender.layouts;
appender = appender
}
..log4j.appenders[..string.lower(appender.type)](loggingEvent,...)
}
}
};
getLevelNumber = function(levelStr){
if(not this.levels[levelStr]) error(..string.format("没有这个日志级别: %s", type(levelStr)),2)
return this.levels[..string.upper(levelStr)].level
};
@{
_get = function(k){
if(type(k) != type.string) return function(){}
if(not this.levels[..string.upper(k)]) return function(){};
this.callLevel = ..string.upper(k)
return this.console
}
}
}
/**intellisense(log4j.Logger)
Logger(loggerCategory) = !newLog4j
Logger(loggerCategory) = 取得log4j实例 @loggerCategory = 'default' /*日志类别*/ ,config/*配置*/
end intellisense**/
/**intellisense(!newLog4j.)
callLevel = 当前call的level级别
loggerCategory = 日志类别
defaultLevel= 输出日志级别
getLevelNumber(levelStr) = 取当前日志级别数字
trace(msg) = {level=2;color = 灰色}; \n @msg{string}
debug(msg) = {level=3;color = 淡淡绿色}; \n @msg{string}
info(msg) = {level=4;color = 湖蓝色}; \n @msg{string}
warn(msg) = {level=5;color = 淡黄色}; \n @msg{string}
error(msg) = {level=6;color =红色}; \n @msg{string}
fatal(msg) = {level=7;color = 淡绿色}; \n @msg{string}
mark(msg) = {level=8;color = 蓝色}; \n @msg{string}
end intellisense**/