Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / log4js / examples / example-connect-logger.js
1 //The connect/express logger was added to log4js by danbell. This allows connect/express servers to log using log4js.
2 //https://github.com/nomiddlename/log4js-node/wiki/Connect-Logger
3
4 // load modules
5 var log4js = require('log4js');
6 var express = require("express");
7 var app = express();
8
9 //config
10 log4js.configure({
11         appenders: [
12                 { type: 'console' },
13                 { type: 'file', filename: 'logs/log4jsconnect.log', category: 'log4jslog' }
14         ]
15 });
16
17 //define logger
18 var logger = log4js.getLogger('log4jslog');
19
20 // set at which time msg is logged print like: only on error & above
21 // logger.setLevel('ERROR');
22
23 //express app
24 app.configure(function() {
25         app.use(express.favicon(''));
26         // app.use(log4js.connectLogger(logger, { level: log4js.levels.INFO }));
27         // app.use(log4js.connectLogger(logger, { level: 'auto', format: ':method :url :status' }));
28
29         //### AUTO LEVEL DETECTION
30         //http responses 3xx, level = WARN
31         //http responses 4xx & 5xx, level = ERROR
32         //else.level = INFO
33         app.use(log4js.connectLogger(logger, { level: 'auto' }));
34 });
35
36 //route
37 app.get('/', function(req,res) {
38         res.send('hello world');
39 });
40
41 //start app
42 app.listen(5000);
43
44 console.log('server runing at localhost:5000');
45 console.log('Simulation of normal response: goto localhost:5000');
46 console.log('Simulation of error response: goto localhost:5000/xxx');