Skip to content
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

Support option for ignoring paths #26

Closed
deedubs opened this issue Nov 10, 2017 · 5 comments · Fixed by #30
Closed

Support option for ignoring paths #26

deedubs opened this issue Nov 10, 2017 · 5 comments · Fixed by #30

Comments

@deedubs
Copy link
Contributor

deedubs commented Nov 10, 2017

Our hapi servers export a /healthz it would be nice if we could omit those requests from the logs.

Would you be open to a PR for this functionality?

I know another option would be to pipe to a filter but I wanted to see the appetite for this built in.

@mcollina
Copy link
Collaborator

Definitely, you might want to use find-my-way to match the routes.

@davidmarkclements
Copy link
Collaborator

related: pinojs/pino-http#40 (@mcollina - perhaps not implementation but the idea.. path ignoring)

@tiagoalves
Copy link

I need to silence our /healthz polling logs as well and tried to use the new ignorePaths feature in PR #30. However, it's not flexible enough for my use case since it matches the routes against request.url.path which includes the request's query params but my query params can have dynamic values.

Just in case it helps someone in the future, I ended up silencing our logs with this micro hapi plugin:

/**
 * A minimal plugin that silences the `hapi-pino`
 * response log for the `/healthz` route.
 */
exports.plugin = {
  register: async (server, options) => {
    server.ext('onPreResponse', (request, h) => {
      if (request.url.pathname === '/healthz') {
        request.logger.level = 'silent'
      }
      return h.continue
    })
  },
  name: 'health-log-silencer',
  version: '1.0.0'
}

@paulovieira
Copy link
Contributor

The ignorePaths option is useful for sure (another typical use case would be paths relative to static files). But it could be a bit more useful if the path could be given with a wildcard. Exemple:

ignorePaths: ['/static*']

In this case the comparison could be done with startsWith instead of equality.

@muuhoffman
Copy link

I was still struggling with this and this worked well for me in the pino-http or express-pino-logger (which just uses pino-http) library:

const expressLogger = expressPino({
  autoLogging: {
    ignorePaths: ["/_next"],
    getPath: (req) => {
      if (/_next/.test(req.url)) {
        return "/_next"
      }
      return req.url
    }
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants