diff --git a/src/client.js b/src/client.js index dba11aef..3ef2108b 100644 --- a/src/client.js +++ b/src/client.js @@ -77,7 +77,8 @@ Client.prototype.emit = function(event, data) { if (this.sockets !== null) { this.sockets.in(this.id).emit(event, data); } - if ((this.config || {}).log === true) { + var config = this.config || {}; + if (config.log === true) { if (event == "msg") { var target = this.find(data.chan); if (target) { diff --git a/src/clientManager.js b/src/clientManager.js index 18984b17..127415d0 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -81,7 +81,7 @@ ClientManager.prototype.addUser = function(name, password) { var user = { user: name, password: password || "", - logs: false, + log: false, networks: [] }; fs.mkdirSync(path); diff --git a/src/log.js b/src/log.js index c0ec4f3c..7da01d72 100644 --- a/src/log.js +++ b/src/log.js @@ -3,44 +3,43 @@ var mkdirp = require("mkdirp"); var moment = require("moment"); var Helper = require("./helper"); -module.exports = { - write: function(user, network, chan, msg) { - var path = Helper.HOME + "/users/" + user + "/logs/" + network; - try { - mkdirp.sync(path); - } catch(e) { - return; - } - - var config = Helper.getConfig(); - 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 + "] "; - - var type = msg.type.trim(); - if (type == "message" || type == "highlight") { - // Format: - // [2014-01-01 00:00:00] 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; - } - } - - fs.appendFile( - path + "/" + chan + ".log", - line + "\n", - function(e) { - if (e) { - console.log("Log#write():\n" + e) - } - } - ); +module.exports.write = function(user, network, chan, msg) { + try { + var path = Helper.HOME + "/logs/" + user + "/" + network; + mkdirp.sync(path); + } catch(e) { + console.log(e); + return; } + + var config = Helper.getConfig(); + 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 + "] "; + + var type = msg.type.trim(); + if (type == "message" || type == "highlight") { + // Format: + // [2014-01-01 00:00:00] 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; + } + } + + fs.appendFile( + path + "/" + chan + ".log", + line + "\n", + function(e) { + if (e) { + console.log("Log#write():\n" + e) + } + } + ); };