Giter Site home page Giter Site logo

Comments (16)

floatingLomas avatar floatingLomas commented on September 27, 2024

That'd be cool - why don't you fork it, do it, and submit a pull request. :)

from express-winston.

mbonig avatar mbonig commented on September 27, 2024

Did this ever happen?

from express-winston.

mbonig avatar mbonig commented on September 27, 2024

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.

rosston avatar rosston commented on September 27, 2024

@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.

hasancansaral avatar hasancansaral commented on September 27, 2024
...
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.

rosston avatar rosston commented on September 27, 2024

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.

rosston avatar rosston commented on September 27, 2024

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.

hasancansaral avatar hasancansaral commented on September 27, 2024

@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.

rosston avatar rosston commented on September 27, 2024

@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.

hasancansaral avatar hasancansaral commented on September 27, 2024

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.

oleiba avatar oleiba commented on September 27, 2024

+1

from express-winston.

adamcohen avatar adamcohen commented on September 27, 2024

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.

mbonig avatar mbonig commented on September 27, 2024

@adamcohen That's a good question. I don't recall what I was thinking at the time.

from express-winston.

adamcohen avatar adamcohen commented on September 27, 2024

@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.

mbonig avatar mbonig commented on September 27, 2024

@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.

mi-mazouz avatar mi-mazouz commented on September 27, 2024

any update? this feature is a must to have!

from express-winston.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.