JavaScript 写 Log 类的具体实现

JavaScript 写 Log 类的具体实现

   由于现在jscript 编写方式比以外负责很多,很多时候都比较难以调试。 为了方便日常程序中的调试,摆弄些下面写Log Class 将需要内容记录下来。
   下面就是具体源代码,此Class 只能在 IE浏览器使用。
 1 LogClass.prototype  =  {
 2          
 3          initialize :  function (){
 4              
 5               try {
 6                  
 7                   this ._fso  =   "" ;   // File 操作对象
 8 
 9                   this ._folderspec  =   "" ;   //  类 fileclass 处理路径
10 
11                   this ._fso  =   new  ActiveXObject( " Scripting.FileSystemObject " );  //  建立 ActiveXObject 对象
12                  
13                   this ._objDate  =   new  Date();
14 
15                   this ._DateString  =    this ._objDate.format( " yyMMdd " );
16 
17                   this ._DateString  =   " c:\\ "   +   this ._DateString  +   " .log "  ;
18 
19                   this ._folderspec  =   this ._DateString;
20                  
21 
22              } catch (e){
23                  
24                  alert( " file Class initialize Error  :  " +  e.number  + "   " +  e.description);
25 
26              }
27 
28          },
29          TRACE :  function (Content){
30              
31               try {
32 
33                   this .OpenTextFile( 8 , true );
34 
35                  _objDate  =   new  Date();
36                  
37                  _dateString  =  _objDate.format( " yyyy-MM-dd hh:mm:ss " );
38 
39                   this ._otf.WriteLine(_dateString + " || " + Content);
40 
41                   this ._otf.close();
42 
43              } catch (e){
44 
45                   this ._otf.Close();
46                  
47                  alert( " file Class TRACE Error  :  " +  e.number  + "   " +  e.description);
48              
49              }
50          
51          },
52          OpenTextFile :  function (IOmode,format){
53 
54               try {
55                  
56                   this ._otf  =   this ._fso.OpenTextFile( this ._folderspec,IOmode, true ,format);
57 
58              } catch (e){
59 
60                   this ._otf.Close();
61 
62                  alert( " file Class OpenTextFile Error  :  " +  e.number  + "   " +  e.description);
63 
64              }
65          
66          }
67 
68  };




MK-TIANYI

你可能感兴趣的:(JavaScript 写 Log 类的具体实现)