Comments (16)
That'd be cool - why don't you fork it, do it, and submit a pull request. :)
from express-winston.
Did this ever happen?
from express-winston.
So, with the current version, this process can be supported pretty easily with lodash:
requestFilter: function (originalObj, propName) {
return _.get(originalObj, propName);
}
from express-winston.
@mbonig Looks like you figured out it didn't happen. 😃 Your solution (thanks for posting it!) certainly makes it easy for someone to do it themselves in their app.
I've been swamped recently, but I'll try to take a stab at getting this (and #62) supported by default soon. It's not quite as easy as just using _.get
in the module though, since user-provided requestFilter
and responseFilter
should probably get called with the top level object (presumably already trimmed to the specified sub-properties). Sorry, talking myself through it right here. I think I just described the only complexity.
from express-winston.
...
requestFilter: function (req, propName) {
return (
propName == 'user' ?
req[propName]['email'] :
req[propName]
);
},
...
did the trick for me. Actually, the documentation could mention this usage a bit more. I'll fork it and open a PR asap. Maybe this issue can be Closed?
from express-winston.
Indeed, that is an easy solution that anyone can do themselves. And thank you for noting it! But it's not quite as easy as
...
requestWhitelist: ['user.email']
...
I know it's been a month since I said I'd work on it, but I swear I really do plan on working on it soon. I'm just often swamped!
from express-winston.
Sorry! I wasn't clear. My snippet is what I want the usage to be like. I haven't implemented it yet. But here's how I would expect that to result in the log:
{
req: {
user: {
email: 'email value'
}
}
}
Does that match your expectation? I'm open to suggestions.
from express-winston.
@rosston Ah, I see. And yes, that would be the behaviour I expect. However, I think that a feature would be useful that could enable one to change key names/nested structure. For example, that would be great if I could log the user email as:
{
req: {
user: {
email: '<emailValue>'
}
}
}
or even:
{
req: {
user: '<emailValue>'
}
}
That was my requirement for the case that one of my projects using basic http auth kept the user in the req
as a simple key-value for the key user
, while another project had the user
as a nested json in the req
, both of which were logging to the same Elasticsearch, so we wanted to keep the log format unified.
from express-winston.
@hasancansaral (Sorry, late reply.) That is an interesting use-case you have there. I can understand the problem, but that seems like a fairly niche requirement to me.
As always, I could be wrong (and am happy to be!). If I am, please feel free to open a separate issue. I feel like the solutions for your use-case and original issue here would be very different.
from express-winston.
I agree that this is quite a different requirement, and should be considered in a different issue, or feature request, whatever that is 😋 And it also has a workaround, one can put the data into the req
in whatever format they require, which will automatically handle the requirement.
from express-winston.
+1
from express-winston.
So, with the current version, this process can be supported pretty easily with lodash:
requestFilter: function (originalObj, propName) { return _.get(originalObj, propName); }
@mbonig how exactly does the above allow you to define a blacklist with user.email
and have it stripped out from the logs? It just seems like the above will allow you to fetch the propName
from originalObj
and no actual filtering is performed.
from express-winston.
@adamcohen That's a good question. I don't recall what I was thinking at the time.
from express-winston.
@mbonig thanks for the response - I was sitting here scratching my head trying to think of what piece of the puzzle I was missing to make this filtering happen using only _.get()
. At least now I know there's additional logic required to implement filtering.
from express-winston.
@adamcohen So, I think where my head was:
_.get() will take care of nested property names, so 'user.email' (https://lodash.com/docs/4.17.11#get) and allow you a very simple implementation on that requestFilter function.
... but hey, two years ago =-}
from express-winston.
any update? this feature is a must to have!
from express-winston.
Related Issues (20)
- 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
- How to retrieve and log authenticated user in a React.JS / Next.JS application?
- SPDY > Express.JS > Next.JS don't show path details
- Conditional Whitelist for Response body?
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.