hardlounge/src/log.js

46 lines
1.0 KiB
JavaScript
Raw Normal View History

2014-09-16 19:47:01 +00:00
var config = require("../config");
var fs = require("fs");
var mkdirp = require("mkdirp");
var moment = require("moment");
var Helper = require("./helper");
module.exports = {
2014-09-16 20:06:13 +00:00
write: function(user, network, chan, msg) {
var path = Helper.resolveHomePath("users", user, "logs", network);
2014-09-16 19:47:01 +00:00
try {
mkdirp.sync(path);
} catch(e) {
return;
}
var format = (config.logs || {}).format || "YYYY-MM-DD HH:mm:ss";
var tz = (config.logs || {}).timezone || "UTC+00:00";
var time = moment().zone(tz).format(format);
var line = "[" + time + "] ";
2014-09-28 00:14:52 +00:00
var type = msg.type.trim();
if (type == "message" || type == "highlight") {
2014-09-16 19:47:01 +00:00
// Format:
// [2014-01-01 00:00:00] <Arnold> Put that cookie down.. Now!!
line += "<" + msg.from + "> " + msg.text;
} else {
// Format:
// [2014-01-01 00:00:00] * Arnold quit
line += "* " + msg.from + " " + msg.type;
if (msg.text) {
line += " " + msg.text;
}
}
try {
fs.appendFile(
2014-09-16 20:06:13 +00:00
path + "/" + chan + ".log",
2014-09-16 19:47:01 +00:00
line + "\n"
);
} catch(e) {
return;
}
}
};