-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogger.js
More file actions
32 lines (29 loc) · 722 Bytes
/
Logger.js
File metadata and controls
32 lines (29 loc) · 722 Bytes
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
var fs = require('fs');
var Logger=exports.Logger=function(enabled,file){
this.enabled=enabled;
this.logfile=-1;
var self=this;
if(enabled){
this.logfile=fs.createWriteStream(file);
}
}
Logger.prototype.log=function(msg){
process.stdout.write(msg+"\n");
if(this.enabled== 1 && this.logfile !=-1){
this.logfile.write(msg+"\n");
}
}
Logger.prototype.close=function(){
if(this.enabled==1 && this.logfile !=-1){
this.logfile.end();
}
}
Logger.prototype.hook=function(){
var self=this;
if(this.enabled==1 && this.logfile !=-1){
console.log=function(msg){
self.log(msg);
//process.stdout.write(msg+"\n");
}
}
}