40 lines
942 B
Plaintext
40 lines
942 B
Plaintext
// log 日志
|
|
import fsys
|
|
import fsys.log
|
|
import time
|
|
|
|
var getToday = function(){
|
|
var $now = time.now() //当前时间
|
|
return "" ++ $now.year ++ $now.month ++ $now.day
|
|
}
|
|
|
|
var todayLogFile = function( name ) {
|
|
|
|
var appDataPath = string.getenv("APPDATA");
|
|
var appPath = appDataPath ++ "/" ++ name;
|
|
if (! io.exist( appPath )) {
|
|
fsys.createDir( appPath )
|
|
}
|
|
return appPath ++ "/" ++ name ++ "." ++ getToday() ++ ".log"
|
|
}
|
|
|
|
|
|
class log {
|
|
ctor( name ){
|
|
|
|
path = todayLogFile(name);
|
|
|
|
this = ..fsys.log(path) //调用基类构造对象原型
|
|
this.basePrint = this.print;
|
|
};
|
|
|
|
print = function(...){
|
|
var t = ..time.now()
|
|
t.format="%Y%m%d-%H%M%S ";
|
|
|
|
var args = {...}
|
|
..table.insert(args, tostring(t)) // 通常时间非重要信息,以...作视觉区分方便查看
|
|
|
|
this.basePrint( ..table.unpack(args) )
|
|
};
|
|
} |