Skip to content

@microp11 /gist:2533910
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
var Log = function () {
this.fs = require('fs');
this.initialized = false;
}
Log.prototype.setLogPathName = function (filename) {
this.filename = filename;
try {
this.fs.unlinkSync(this.filename);
}
catch (e) {
console.log(e);
}
var fd = this.fs.openSync(this.filename, "a+", 0666);
this.fs.writeSync(fd, "<html><head><style type=\"text/css\">" +
"p {white-space:nowrap; font-family: Courier New; font-size: 12px; line-height:20%;}" +
".time {color:orange;} .a1 {color:red;} .a2 {color:blue;} .a3 {color:green;}" +
"</style></head><body>");
this.fs.closeSync(fd);
this.initialized = true;
}
Log.prototype.logLine = function (msg) {
if (!this.initialized) {
console.log("You must call Log.setFullFilename() first.");
}
msg = msg.replace("{0}", "<span class=\"a1\">" + arguments[1] + "</span>");
msg = msg.replace("{1}", "<span class=\"a2\">" + arguments[2] + "</span>");
msg = msg.replace("{2}", "<span class=\"a3\">" + arguments[3] + "</span>");
var fd = this.fs.openSync(this.filename, "a+", 0666);
this.fs.writeSync(fd, "<p>" + "<span class=\"time\">" + getTime() + "</span>: " + msg + "</p>");
this.fs.closeSync(fd);
}
var getTime = function() {
var dTime = new Date();
var hour = dTime.getHours() + "";
if (hour.length == 1) { hour = "0" + hour; }
var minute = dTime.getMinutes() + "";
if (minute.length == 1) { minute = "0" + minute; }
var seconds = dTime.getSeconds() + "";
if (seconds.length == 1) { seconds = "0" + seconds; }
var ms = dTime.getMilliseconds() + "";
if (ms.length == 1) { ms = "00" + ms; }
else if (ms.length == 2) { ms = "0" + ms; }
return hour + ":" + minute + ":" + seconds + ":" + ms;
}
module.exports = new Log();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.