hapijs / good

hapi process monitoring
Other
525 stars 161 forks source link

Good event filters not getting applied in log file #605

Closed bhawna91 closed 5 years ago

bhawna91 commented 5 years ago

I created a new npm package for suppressing response event from the log file. The transform function for the stream in the package is -

    _transform(data, enc, next) {

        if (data.event === 'response' && data.config.suppressResponseEvent === true) {

            return next();
        }

        return next(null, data);
    } 

and is exposed as Filter

This is how I set the suppressResponseEvent config field in server.js file -

var routeConfig = {
    plugins: {
        good: {
            suppressResponseEvent: true
        }
    }
};
server.route({
    method: "GET",
    path: "/user",
    handler: async (request, h) => {
           .....some code here
        config: routeConfig
  });

In good-options , I am using this filter -

     fileReporter: [{
            module: 'good-squeeze',
            name: 'Squeeze',
            args: [{ request: '*', response : '*', ops: '*' , log: '*'}]
        }, {
            module: 'good-squeeze',
            name: 'SafeJson'
        },
        {
           module: 'my-custom-package',
           name: 'Filter',
           args: [{ log: '*', response: '*' }]
         },
        {
            module: 'rotating-file-stream',
            args: ['mylog.log',
            {
                size: '50M',
                path: '/log'
            }]
        }
        ]

Code runs fine. I was thinking that the response event for the endpoint should not be present in log after these changes, but its still there. The config object is populated properly though in the event. What am I missing?

bhawna91 commented 5 years ago

@Nargonath any idea?

Nargonath commented 5 years ago

@bhawna91 Nope sorry, I haven't been using Good lately.

arb commented 5 years ago

What's data.config in _transform?

bhawna91 commented 5 years ago

@arb - data.config is the config passed to the events of /user endpoint . The routeConfig above. I am trying to suppress the response events based on this config by using suppressResponseEvent: true

The response event has the config populated -

{event:"response",.......,config:{suppressResponseEvent:true}}

and the expectation is that if

(data.event === 'response' && data.config.suppressResponseEvent === true){return next();} 

should be filtering out this event . But it still appears in the log.

Nargonath commented 5 years ago

@bhawna91 Please, use markdown syntax for code block otherwise it is really hard to read. You can even use syntax identifier to add syntax highlighting: https://help.github.com/articles/creating-and-highlighting-code-blocks/

bhawna91 commented 5 years ago

done.

arb commented 5 years ago

Do you have any other reporters writing to '/log'? What you have there should be working.

bhawna91 commented 5 years ago

Yes I have another reporter writing to /log to another file.

arb commented 5 years ago

That's likely where the extra log entries are coming from.

mpeperos commented 5 years ago

@bhawna91 Is it working?

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.