-
Notifications
You must be signed in to change notification settings - Fork 201
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
Logging Error object has a difficult to read output #773
Comments
I found a few problems with this issue:
|
I have the same problem for objects I pass to the logger.
The output I get is: For more complex objects the output is almost unreadable. |
Thanks for reporting the issue @shalbert94 and @jankalthoefer. A workaround would be to wrap the error stack inside a simple object: const functions = require('firebase-functions');
try {
throw new Error('Message from the thrown error.');
} catch (err) {
functions.logger.error('Logged message', { stack: err.stack });
} I suspect that this isn't a satisfying answer. FWIW, you can always use a custom logger that better fits your use case. |
For anyone who'd like a potentially more complete solution, the following module is what I've come up with.
Explanation:
Because of the API's implementation, ES6 classes are not converted to a
comes in. I couldn't find a good approach for identifying ES6 classes, as opposed to plain objects, so instead, it made sense to just clone enumerable properties of every object. Opinions:
Edit: Replaced one solution with another I think is better |
@shalbert94 Thanks for making the suggestions. I think that makes for a good FR. I don't think we can prioritize the work ATM, but feel free to check in with us if you have some time to contribute. |
I thought I was taking crazy pills. Thanks for the workaround @shalbert94 . In my case, errors would just go missing and show up as empty objects - but only sometimes. Took me quite a number of hours to find this issue. |
Related issues
[REQUIRED] Version info
node: 10.22.0
firebase-functions: 3.11.0
firebase-tools: 8.9.0
firebase-admin: 8.13.0
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
Run the test case. For example:
[REQUIRED] Expected behavior
Something like:
[REQUIRED] Actual behavior
Were you able to successfully deploy your functions?
Yes, it deploys fine. This is about logging errors in a way that is easier to read.
The actual output isn't ideal because the the logged
message
("Logged message ") is concatenated with theError
object'smessage
("Message from the thrown error.") andstack
. It's clear this happens because Error isn't a simple object, which means the logger won't interpret it as a "jsonPayload". However, this makes reading errors more difficult. Is there a way to log errors so that the output is more like the following?This is just the tip of the iceberg, because I'd like to create custom error
class
es thatextends
theError
class, but those print just as poorly.The text was updated successfully, but these errors were encountered: