Skip to content

Commit

Permalink
增加log4js
Browse files Browse the repository at this point in the history
  • Loading branch information
hamuPP committed Jul 5, 2016
1 parent 15ee283 commit 00c3bba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var routes = require('./routes');
var http = require('http');
var path = require('path');
var product = require('./routes/product');
var log4js = require('log4js');

//var webRouter = require('./webRouter');

Expand Down Expand Up @@ -129,6 +130,22 @@ app.locals.splitString = function(sSeptation, sStr) {
/*新版本*/
app.get('/indexv2',index.indexv2);

log4js.configure({
appenders: [
{
type: 'file', //文件输出
filename: 'logs/access.log',
maxLogSize: 1024,
backups: 3,
category: 'normal'
}
],
replaceConsole: true
});
var logger = log4js.getLogger('normal');
logger.setLevel('TRACE');
app.use(log4js.connectLogger(logger, {level: log4js.levels.TRACE}));

http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
1 change: 1 addition & 0 deletions logs/access.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[2016-07-05 13:14:17.515] [TRACE] normal - ::1 - - "GET /imgs/justice.jpg HTTP/1.1" 404 29 "http://localhost:3001/my" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"

0 comments on commit 00c3bba

Please sign in to comment.