-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request.log(err) show an empty object #2744
Comments
Does somebody has a opinion? :) |
Well console.error would not show up in logging if you use Good for instance, I do |
@AdriVanHoudt Thanks for you reply 👍 Yes, but the stacktrace would be good to have as well, but the request log purposely stringified it here |
It can, we just need to change |
@gergoerdosi It is not that json can't be prettified, it is that the Error.stack contains breaks and they will be converted to \n in JSON.stringify |
Can you please add a sample code? I'm trying to reproduce the problem, but the stack is displayed correctly for me: var Hapi = require('hapi');
// Create a server with a host and port
var server = new Hapi.Server({ debug: { request: ['error'] } });
server.connection({
host: 'localhost',
port: 8080
});
// Add the route
server.route({
method: 'GET',
path:'/hello',
handler: function (request, reply) {
request.log(['error'], new Error('test'));
reply('hello');
}
});
// Start the server
server.start(function () {
console.log('Server running at:', server.info.uri);
}); This outputs: $ node index.js
Server running at: http://localhost:8080
Debug: error
Error: test
at server.route.handler (/index.js:15:32)
at Object.internals.handler (/node_modules/hapi/lib/handler.js:93:36)
at /node_modules/hapi/lib/handler.js:28:23
at internals.Protect.run (/node_modules/hapi/lib/protect.js:56:5)
at exports.execute (/node_modules/hapi/lib/handler.js:22:22)
at /node_modules/hapi/lib/request.js:377:13
at iterate (/node_modules/hapi/node_modules/items/lib/index.js:35:13)
at done (/node_modules/hapi/node_modules/items/lib/index.js:27:25)
at /node_modules/hapi/node_modules/hoek/lib/index.js:841:22
at process._tickDomainCallback (node.js:381:11) |
I did not understand the code properly and how hapi.js works together with good and good-console. I should have mentioned that I used good. There is actually no error. To help on my shame for creating this issue, I donated 50 danish kroners to red cross to help children in syria. |
@gergoerdosi try using Good console and then you will see what he means and yeah true it will convert to \n but there is no other way to log it to let's say a log file otherwise, you can parse it back into multiline on read. Also no shame! Cool to donate though |
I dug into it some more, now that i knew it was handle more by I thought it was the same output, but it is not. I wanted to just log my javascript errors, but it seems not that easy. |
Good-console will do that for you, but as @gergoerdosi showed just doing the log, hapi will print it out for you nicely, or you can make your fork of good-console that does as you described in your original post with the console.error thing |
Changing If this gets fixed in json-stringify-safe, we can look into changing the code in good-console to support Error. |
@gergoerdosi what does passing the property names do? (not familiar with safestringify) |
@AdriVanHoudt Properties in Error objects are non-emurable, that's why Error objects can't be stringified. Whitelisting the property names is a little trick that makes
Not sure this is the best way to solve this problem, but it's one. |
I see, is it perf? |
Not really. I just did a test now, Anyway, this is not a hapi issue. @kevinsimper: Open an issue in good-console if you want and we can continue the discussion there. |
The problem is not only with But the problem is not either in I solved it anyways in a hacky way, where i change the Error prototype to be enumerable.
and then not using good-console for the request.log, but using the built in
|
So is changing Error object the way to solve this problem? Is there a better way? |
That is because you can't stringify an Error, but Hapi.js does try anyways because
typeof error === 'object'
.I propose that
error.stack
looks bad, it should just console.error without JSON.stringifydata instanceof Error
The text was updated successfully, but these errors were encountered: