Open joshliptzin opened 7 years ago
Hey! I just stumbled on this project and it looks like it isn't maintained. I know also that this question was posted a long time ago, but I did want to offer my two cents.
Express captures errors and doesn't pass them to "normal" middleware, but only passes errors to middleware functions that accept four arguments. It's quirky, I know. Anyway, I am guessing that you could solve this by doing:
const logger = scribe.express.logger();
// Log successful requests
app.use(logger);
// Also log requests that go to error middleware
app.use(function(err, req, res, next) {
logger(req, res, next);
});
However, that doesn't seem particularly useful, as the built-in logger doesn't seem to have any way of accepting and printing the error message. So you'd have to do some custom middleware, like so:
// Log successful requests
app.use(scribe.express.logger());
// Custom error-handling middleware
app.use(function(err, req, res, next) {
process.console
.time()
.tag(
{ msg: 'Express', colors: 'cyan' },
{ msg: req.ip, colors: 'red' },
{ msg: req.method, colors: 'green' },
{ msg: (/mobile/i.test(req.headers['user-agent']) ? 'MOBILE' : 'DESKTOP'), colors: 'grey' }
)
.error(err.message);
next(err);
});
Thank you, I found a different solution, but I do appreciate the follow up. If I decide to try scribe again, this definitely looks like it will be useful.
Best, Josh
On Wed, Sep 20, 2017 at 5:50 PM, Matt Miller notifications@github.com wrote:
Hey! I just stumbled on this project and it looks like it isn't maintained. I know also that this question was posted a long time ago, but I did want to offer my two cents.
Express captures errors and doesn't pass them to "normal" middleware, but only passes errors to middleware functions that accept four arguments. It's quirky, I know. Anyway, I am guessing that you could solve this by doing:
const logger = scribe.express.logger(); // Log successful requestsapp.use(logger); // Also log requests that go to error middlewareapp.use(function(err, req, res, next) { logger(req, res, next); });
However, that doesn't seem particularly useful, as the built-in logger doesn't seem to have any way of accepting and printing the error message. So you'd have to do some custom middleware, like so:
// Log successful requestsapp.use(scribe.express.logger()); // Custom error-handling middlewareapp.use(function(err, req, res, next) { process.console .time() .tag( { msg: 'Express', colors: 'cyan' }, { msg: req.ip, colors: 'red' }, { msg: req.method, colors: 'green' }, { msg: (/mobile/i.test(req.headers['user-agent']) ? 'MOBILE' : 'DESKTOP'), colors: 'grey' } ) .error(err.message); next(err); });
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bluejamesbond/Scribe.js/issues/100#issuecomment-330991181, or mute the thread https://github.com/notifications/unsubscribe-auth/AA9CsinaxbYXgiL2dU_xkeYwuDu7lwNjks5skYiVgaJpZM4Nettz .
-- Josh Liptzin
Thought I would give this a whirl, followed install instructions and examples and could only get it to print successful requests. No error requests showing up in log which is literally the only thing I need this library for. Maybe bad documentation (is anyone still working on this)? Maybe I haven't had enough coffee today but I have been a professional web developer for 15 years and this shouldn't be so difficult. I moved on to log4js and got that up and running in 5 min (even with their incorrect documentation) but I wish it were prettier like Scribe.