Comments (10)
I don't have a PR ready for this yet, but here's what I plan to do:
- Add an
errorWhitelist
that works just like therequestWhitelist
andresponseWhitelist
- Add an
errorFilter
to the options that is used just like therequestFilter
andresponseFilter
- Put the result of the
errorWhitelist
properties being run through theerrorFilter
on anerror
property on the metadata object
from express-winston.
Alternatively, we could approach this by being able to supply an 'error transformer' function that would just transform a received error however anyone might want to transform it, with a default of just returning the given error.
from express-winston.
I think that might be a clearer way. Something like error
as a top-level property? And then there's a special handler that is provided the error object and can return whatever it wants to go on error
?
The only tricky thing there is that the base error object in V8 has no toJSON
method, no enumerable properties, and Object.getOwnPropertyNames
returns ["stack", "message"]
, which excludes the (semi-important) name
property. So if, say, the user decides to simply return the error as is, possibly nothing will show up. Or maybe we just always put the name
and message
properties on the error
object?
I'm expecting to have time tomorrow to work on this specifically, so ideas are welcome!
from express-winston.
After testing this error transform approach in a real application, I think it's a little too dangerous. I think libraries will sometimes throw errors with circular references (e.g., https://github.com/vpulim/node-soap), which causes winston to exceed the max call stack size when trying to serialize the error. In that case, a user of this module would be required to use the errorTransform
if a library they use happens to throw errors with circular references.
I think it would be preferable to have safe defaults, so I'll probably open a new PR later with an errorWhitelist
and errorFilter
as described in #95 (comment).
from express-winston.
@rosston Any updates on this? I'm happy to open a PR, just wanted to check if any prior work outside of #99 had been done.
I'm using VError, and I've recently run into a scenario where I'd like to use something like errorTransform
to add info from VError.info(err)
to my logs.
from express-winston.
@cbaclig No updates/progress on this. It eventually ended up being less of an issue at my day job, so I never got around to it. You're welcome to work on it if you want.
I think my suggested approach in #95 (comment) is probably the best way to go. I really prefer the idea of an errorTransform
, but it seems too prone to developers accidentally introducing server crashes into their app by forgetting to remove circular-dependent properties. errorWhitelist
+ errorFilter
provides a bit more safe-by-default functionality, I think.
from express-winston.
Just realized json-stringify-safe exists, so forget what I said about circular references. We just need to use that module + errorTransform
, and everything will be fine.
from express-winston.
Given the addition of dynamicMeta
in #124, instead of an errorTransform
property, adding a dynamicMeta
that effectively does the same thing seems like it'd accomplish the same thing and keep the interface more consistent between the "normal" logger and the errorLogger. The only difference would be that the function passed to dynamicMeta
for the errorLogger would get an additional err
parameter. e.g.
dynamicMeta: function(err, req, res) { return [Object]; }
Thoughts?
from express-winston.
I think I'm fine with this approach as a customization option, although err
should probably be the last parameter to keep backward compatibility.
Is there any reason not to just always put the entire error (run through json-stringify-safe
) in the metadata (on, say, a rawError
key)?
from express-winston.
Fixed in #139 (via dynamic meta in the error logger) and released in 2.2.0.
from express-winston.
Related Issues (20)
- bodyBlacklist doesn't work for responses HOT 4
- I need to capture both error log object and access log object and send it using slack bot HOT 1
- Allow intialization using an instance of winston HOT 1
- Incorrect TypeScript types: metaField, requestField, responseField
- requestFilter won't filter out body field HOT 4
- log response body based on status code.
- bodyBlacklist mask properties value
- `level` intentionally different from Winston?
- Please upgrade lodash to 4.17.21 to address the vulnerabilities.
- Strange format being logged for request body HOT 6
- sec. vuln.: brackets {{ and }} in URL can trigger template engine HOT 10
- Changing offensive language in code HOT 6
- Request timestamp
- Convert previous Travis yamls to Github Actions
- Ease of Contributions and Repo Maintaince HOT 1
- Log as soon as the request is received
- express-winston disappears in GCP Logs HOT 2
- Issue with `errorLogger` msg always returning `200` for `res.statusCode`
- Issue Api response time not always correct
- Remove responseTime from meta
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-winston.