js 日志类

可以方便记录js 运行时产生中间变量,可以方便跟踪你的代码运行情况

 

代码
1 var Log = function (path)
2 {
3 this .filehand = null ;
4 this .namepath = path;
5 this .begin = function ()
6 {
7 var fso = new ActiveXObject( " Scripting.FileSystemObject " ); // firefox 需要下插件
8   if ( this .namepath == null )
9 var filename = getFileName();
10 else
11 var filename = this .namepath;
12 this .filehand = fso.CreateTextFile(filename + getFileName() + " .txt " , true )
13 }
14 this .end = function ()
15 {
16 this .filehand.Close();
17 }
18 Log.prototype.write = function ()
19 {
20 var args = arguments, argsCount = args.length;
21 if (argsCount == 0 ) {filehand.WriteLine( " 参数为空 " ); filehand.Close(); }
22 for ( var i = 0 ;i < argsCount;i ++ )
23 { try
24 {
25 this .filehand.WriteLine((i + 1 ) + " . " + args[i]);
26 }
27 catch (e)
28 {
29 this .filehand.Close();
30 }
31 }
32 }
33 function getFileName()
34 {
35 var d = new Date();
36 var name = d.getFullYear().toString() + " - " + (d.getMonth() + 1 ).toString() + " - " + d.getDate().toString() + " - " + d.getHours().toString() + " - " + d.getMinutes().toString() + " - " + d.getSeconds().toString() + " - " + Math.round(Math.random() * 10000 );
37 return name // 年-月-日-时-分-秒-随机数
38   }
39 }

 

 

写的一般,大家有好的想法,欢迎交流!

转载于:https://www.cnblogs.com/shouhongxiao/archive/2010/03/03/1677230.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值