Installed log4js as logging framework

This commit is contained in:
Peter 'Pita' Martischka 2011-07-31 18:25:51 +01:00
parent 22b00264d8
commit b30849c2f2
7 changed files with 41 additions and 27 deletions

View File

@ -303,7 +303,7 @@ Class('Pad', {
if(entries[i]==null) if(entries[i]==null)
cleanedEntries.push(entries[i]); cleanedEntries.push(entries[i]);
else else
console.log("WARNING: Found broken chat entry in pad " + _this.id); console.warn("WARNING: Found broken chat entry in pad " + _this.id);
} }
callback(err, cleanedEntries); callback(err, cleanedEntries);

View File

@ -319,11 +319,6 @@ function handleUserInfoUpdate(client, message)
} }
} }
function errlog(name, value)
{
console.error(name+"=" + JSON.stringify(value));
}
/** /**
* Handles a USERINFO_UPDATE, that means that a user have changed his color or name. Anyway, we get both informations * Handles a USERINFO_UPDATE, that means that a user have changed his color or name. Anyway, we get both informations
* This Method is nearly 90% copied out of the Etherpad Source Code. So I can't tell you what happens here exactly * This Method is nearly 90% copied out of the Etherpad Source Code. So I can't tell you what happens here exactly
@ -418,7 +413,7 @@ function handleUserChanges(client, message)
if (Changeset.oldLen(changeset) != prevText.length) if (Changeset.oldLen(changeset) != prevText.length)
{ {
console.log("Can't apply USER_CHANGES "+changeset+" with oldLen " + Changeset.oldLen(changeset) + " to document of length " + prevText.length); console.warn("Can't apply USER_CHANGES "+changeset+" with oldLen " + Changeset.oldLen(changeset) + " to document of length " + prevText.length);
client.json.send({disconnect:"badChangeset"}); client.json.send({disconnect:"badChangeset"});
callback(); callback();
return; return;

View File

@ -19,6 +19,9 @@
* limitations under the License. * limitations under the License.
*/ */
var log4js = require('log4js');
var messageLogger = log4js.getLogger("message");
/** /**
* Saves all components * Saves all components
* key is the component name * key is the component name
@ -54,7 +57,7 @@ exports.setSocketIO = function(_socket)
client._send = client.send; client._send = client.send;
client.send = function(message) client.send = function(message)
{ {
console.log(new Date().toUTCString() + ": message to " + client.id + ": " + JSON.stringify(message)); messageLogger.info("to " + client.id + ": " + JSON.stringify(message));
client._send(message); client._send(message);
} }
@ -68,14 +71,14 @@ exports.setSocketIO = function(_socket)
{ {
if(message.protocolVersion && message.protocolVersion != 2) if(message.protocolVersion && message.protocolVersion != 2)
{ {
console.error("Protocolversion header is not correct:" + JSON.stringify(message)); messageLogger.warn("Protocolversion header is not correct:" + JSON.stringify(message));
return; return;
} }
//route this message to the correct component, if possible //route this message to the correct component, if possible
if(message.component && components[message.component]) if(message.component && components[message.component])
{ {
console.log(new Date().toUTCString() + ": message from " + client.id + ": " + JSON.stringify(message)); messageLogger.info("from " + client.id + ": " + JSON.stringify(message));
//check if component is registered in the components array //check if component is registered in the components array
if(components[message.component]) if(components[message.component])
@ -85,7 +88,7 @@ exports.setSocketIO = function(_socket)
} }
else else
{ {
console.error("Can't route the message:" + JSON.stringify(message)); messageLogger.error("Can't route the message:" + JSON.stringify(message));
} }
}); });

View File

@ -32,6 +32,7 @@ var express = require('express');
var path = require('path'); var path = require('path');
var minify = require('./utils/Minify'); var minify = require('./utils/Minify');
var formidable = require('formidable'); var formidable = require('formidable');
var log4js = require('log4js');
var exportHandler; var exportHandler;
var importHandler; var importHandler;
var exporthtml; var exporthtml;
@ -48,7 +49,7 @@ try
} }
catch(e) catch(e)
{ {
console.error("Can't get git version for server header\n" + e.message) console.warn("Can't get git version for server header\n" + e.message)
} }
var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)"; var serverName = "Etherpad-Lite " + version + " (http://j.mp/ep-lite)";
@ -74,9 +75,12 @@ async.waterfall([
exportHandler = require('./handler/ExportHandler'); exportHandler = require('./handler/ExportHandler');
importHandler = require('./handler/ImportHandler'); importHandler = require('./handler/ImportHandler');
//set logging //install logging
if(settings.logHTTP) var httpLogger = log4js.getLogger("http");
app.use(express.logger({ format: ':date: :status, :method :url' })); app.configure(function()
{
app.use(log4js.connectLogger(httpLogger, { level: log4js.levels.INFO, format: ':status, :method :url'}));
});
//serve static files //serve static files
app.get('/static/*', function(req, res) app.get('/static/*', function(req, res)
@ -224,7 +228,7 @@ async.waterfall([
{ {
new formidable.IncomingForm().parse(req, function(err, fields, files) new formidable.IncomingForm().parse(req, function(err, fields, files)
{ {
console.log(new Date().toUTCString() + ": DIAGNOSTIC-INFO: " + fields.diagnosticInfo); console.log("DIAGNOSTIC-INFO: " + fields.diagnosticInfo);
res.end("OK"); res.end("OK");
}); });
}); });
@ -264,8 +268,26 @@ async.waterfall([
//we should remove this when the new socket.io version is more stable //we should remove this when the new socket.io version is more stable
io.set('transports', ['xhr-polling']); io.set('transports', ['xhr-polling']);
//reduce the log level var socketIOLogger = log4js.getLogger("socket.io");
io.set('log level', 2); io.set('logger', {
debug: function (str)
{
//supress debug messages
//socketIOLogger.debug(str);
},
info: function (str)
{
socketIOLogger.info(str);
},
warn: function (str)
{
socketIOLogger.warn(str);
},
error: function (str)
{
socketIOLogger.error(str);
},
});
//minify socket.io javascript //minify socket.io javascript
if(settings.minify) if(settings.minify)

View File

@ -38,10 +38,6 @@ exports.dbType = "sqlite";
* This setting is passed with dbType to ueberDB to set up the database * This setting is passed with dbType to ueberDB to set up the database
*/ */
exports.dbSettings = { "filename" : "../var/sqlite.db" }; exports.dbSettings = { "filename" : "../var/sqlite.db" };
/**
* A flag that shows if http requests should be loged to stdout
*/
exports.logHTTP = true;
/** /**
* The default Text of a new pad * The default Text of a new pad
*/ */
@ -93,6 +89,6 @@ for(var i in settings)
else else
{ {
console.error("WARNING: Unkown Setting: '" + i + "'"); console.error("WARNING: Unkown Setting: '" + i + "'");
console.error("If this isn't a mistake, add the default settings for this value to node/settings.js"); console.error("This setting doesn't exist or it was removed");
} }
} }

View File

@ -18,7 +18,8 @@
"clean-css" : "0.2.4", "clean-css" : "0.2.4",
"uglify-js" : "1.0.6", "uglify-js" : "1.0.6",
"gzip" : "0.1.0", "gzip" : "0.1.0",
"formidable" : "1.0.2" "formidable" : "1.0.2",
"log4js" : "0.3.7"
}, },
"version" : "0.0.4" "version" : "0.0.4"
} }

View File

@ -25,9 +25,6 @@
}, },
*/ */
//if true, every http request will be loged to stdout
"logHTTP" : true,
//the default text of a pad //the default text of a pad
"defaultPadText" : "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n", "defaultPadText" : "Welcome to Etherpad Lite!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad Lite on Github: http:\/\/j.mp/ep-lite\n",