Use log4js for logging

Closes #136
This commit is contained in:
Sandro Santilli 2014-03-13 11:52:40 +01:00
parent c4fc010d9b
commit 1f3aca837b
5 changed files with 66 additions and 42 deletions

View File

@ -4,6 +4,7 @@
Enhancements:
* Allow configuring log_format (#131)
* Use log4js for logging (#136)
1.8.3 - 2014-02-10
------------------

10
app.js
View File

@ -24,6 +24,16 @@ global.settings = require(__dirname + '/config/settings');
var env = require(__dirname + '/config/environments/' + ENV);
_.extend(global.settings, env);
global.log4js = require('log4js')
log4js_config = {
appenders: [
{ type: "console", layout: { type:'basic' } }
],
replaceConsole:true
};
log4js.configure(log4js_config);
// kick off controller
if ( ! global.settings.base_url ) global.settings.base_url = '/api/*';
var app = require(global.settings.app_root + '/app/controllers/app')();

View File

@ -73,11 +73,17 @@ Date.prototype.toJSON = function() {
return s;
}
app.use(express.logger({
var loggerOpts = {
buffer: true,
format: global.settings.log_format ||
'[:date] :req[X-Real-IP] :method :req[Host]:url :status :response-time ms -> :res[Content-Type]'
}))
':req[X-Real-IP] :method :req[Host]:url :status :response-time ms -> :res[Content-Type]'
};
if ( global.log4js ) {
app.use(log4js.connectLogger(log4js.getLogger(), _.defaults(loggerOpts, {level:'auto'})));
} else {
app.use(express.logger(loggerOpts));
}
// Set connection timeout
if ( global.settings.hasOwnProperty('node_socket_timeout') ) {

78
npm-shrinkwrap.json generated
View File

@ -1,7 +1,29 @@
{
"name": "cartodb_sql_api",
"version": "1.8.2",
"version": "1.9.0",
"dependencies": {
"underscore": {
"version": "1.3.3"
},
"underscore.string": {
"version": "1.1.6",
"dependencies": {
"underscore": {
"version": "1.1.7"
}
}
},
"pg": {
"version": "2.6.2",
"dependencies": {
"generic-pool": {
"version": "2.0.3"
},
"buffer-writer": {
"version": "1.0.0"
}
}
},
"express": {
"version": "2.5.11",
"dependencies": {
@ -24,41 +46,6 @@
}
}
},
"underscore": {
"version": "1.3.3"
},
"underscore.string": {
"version": "1.1.6",
"dependencies": {
"underscore": {
"version": "1.1.7"
}
}
},
"pg": {
"version": "2.6.2",
"dependencies": {
"generic-pool": {
"version": "2.0.3"
},
"buffer-writer": {
"version": "1.0.0",
"dependencies": {
"cloned": {
"version": "0.0.1",
"dependencies": {
"rmdir": {
"version": "1.0.0"
}
}
},
"async": {
"version": "0.2.9"
}
}
}
}
},
"cartodb-redis": {
"version": "0.3.0",
"dependencies": {
@ -116,6 +103,25 @@
"lru-cache": {
"version": "2.2.4"
},
"log4js": {
"version": "0.6.12",
"dependencies": {
"async": {
"version": "0.1.15"
},
"semver": {
"version": "1.1.4"
},
"readable-stream": {
"version": "1.0.26-2",
"dependencies": {
"string_decoder": {
"version": "0.10.25-1"
}
}
}
}
},
"redis": {
"version": "0.7.1"
},

View File

@ -25,7 +25,8 @@
"topojson": "0.0.8",
"oauth-client": "0.2.0",
"node-uuid":"1.3.3",
"lru-cache":"~2.2.2"
"lru-cache":"~2.2.2",
"log4js": "~0.6.10"
},
"devDependencies": {
"redis": "0.7.1",