How can I log any errors from ExpressJS applications to a file?
I know that I can easily log in to Slim Framework using monolog :
$app->get('/tickets', function (Request $request, Response $response) {
$this->logger->addInfo("Something interesting happened");
$mapper = new Simon\TicketMapper($this->db);
$tickets = $mapper->getTickets();
$response->getBody()->write(var_export($tickets, true));
return $response;
});
In Express, I usually log an error on the development console :
Model.findOne(options, function(err, doc) {
var output = {};
if (err) {
console.log("Error retrieving doc: " + err);
}
But on my production server, I need a useful log file when the application does not work correctly.
Any ideas?
In Express, app.jsthis has:
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
But how do I turn on production? Is it just like a monologue, what do I need?