2014-06-20 13:57:11 +00:00
|
|
|
var config = require("../config") || {};
|
|
|
|
var fs = require("fs");
|
|
|
|
var moment = require("moment");
|
|
|
|
|
|
|
|
module.exports = function log(chan, msg) {
|
2014-06-23 17:28:36 +00:00
|
|
|
var client = chan.network.client;
|
|
|
|
if (!client.config.log) {
|
2014-06-20 13:57:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var network = chan.network.name;
|
2014-06-23 17:28:36 +00:00
|
|
|
var dir = "logs/";
|
|
|
|
|
|
|
|
dir += client.name + "/";
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
dir += network + "/";
|
2014-06-20 13:57:11 +00:00
|
|
|
if (!fs.existsSync(dir)) {
|
2014-06-23 17:28:36 +00:00
|
|
|
fs.mkdirSync(dir);
|
2014-06-20 13:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var date = moment().format("YYYY-MM-DD HH:mm");
|
|
|
|
var line = "[" + date + "] ";
|
|
|
|
if (msg.type == "normal") {
|
|
|
|
line += "<"
|
|
|
|
+ msg.from + "> "
|
|
|
|
+ msg.text;
|
|
|
|
} else {
|
|
|
|
line += "* "
|
|
|
|
+ msg.from + " "
|
|
|
|
+ msg.type + " "
|
|
|
|
+ msg.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
var file = dir + chan.name + ".log";
|
|
|
|
fs.appendFile(
|
|
|
|
file,
|
|
|
|
line + "\n"
|
|
|
|
);
|
|
|
|
};
|