Problem
I have a node.js express app with log4js configured.
Running the app in browser (this works normally) calls error middleware because i do a next(err)
inside the matching router.
What happend
After calling the apps url the console.log(logger)
function outputs the object logger
to console - logger object is valid - and after that Log 2 test
appears also.
But when is look into the server.log
file i can see only one line of logging:
[2014-08-22 13:15:06.343] [INFO] default - Log 1 test
The second line is missing.
Code
var log4js = require("log4js");
log4js.configure({
appenders: [
{
type: 'file',
filename: "./server.log",
category:"default"
},
{
type: 'console'
}
]
});
var logger = log4js.getLogger("default");
logger.setLevel("DEBUG");
logger.info("Log 1 test");
app = express();
app.use(... some routers)
app.use(function (err, req, res, next) {
console.log(logger);
res.status(500).json({
status: err.status,
message: err.message
});
logger.info("Log 2 test"); // seems not to work
});
Any ideas?