Skip to content
Logixlysia
Esc
↑↓navigate↵open⌘Jpreview
On this page

Log Filtering

Filter logs by level, choose which routes are logged, and hide the access line by path

logFilter restricts which log levels get processed with level, chooses which routes are logged with include and exclude, and hides the access line of chosen paths with accessLine.

Basic usage

logixlysia({
  config: {
    logFilter: {
      level: ['ERROR', 'WARNING']
    }
  }
})

Available levels: ERROR, WARNING, INFO, DEBUG. Any other value, such as 'WARN', makes the plugin throw logixlysia: invalid logFilter config when you construct it.

Omit logFilter, or omit level, and every level is processed.

Reducing volume

logFilter only drops whole levels. To keep a percentage of records instead, or to rescue slow and failed requests that would otherwise be dropped, use sampling, which supports head sampling per level and tail sampling by status, duration, or path.

Choosing which routes are logged

Health checks, metrics scrapes and static assets can outnumber real traffic. exclude silences the routes you name, and include logs only the routes you name.

logixlysia({
  config: {
    logFilter: {
      exclude: ['/health', '/metrics', '/assets/**']
    }
  }
})
logixlysia({
  config: {
    logFilter: {
      include: ['/api/**'],
      exclude: ['/api/internal/**']
    }
  }
})

Both take the same globs as sampling.tail.paths: ** crosses /, while * and ? do not. They match the pathname only, so /health?probe=1 is /health. Precedence, in order:

  • exclude beats include.
  • With a non-empty include, a path it does not match is not logged. That includes a request that no route answers, which is a 404 for a path outside include.
  • An empty array is the same as leaving the key out.
  • A pathname longer than 2048 characters matches no glob, so it is always logged. Otherwise a client could hide requests to an included route by padding the path.

The verdict is made once per request, from the pathname, and covers every record that request writes: the access line, log.* calls in its handler (through log or useLogger()), error lines, and the WebSocket open, message and close lines. Status and level do not change it, so an excluded route that answers 500 writes nothing. Use accessLine when errors on the route should still be logged.

An excluded request does no work to build a record. Its enrichers do not run, nothing is redacted and it takes no part in sampling. The request id is still generated and echoed in the response header.

WebSocket lines match the path you pass to wrapWs, as you wrote it. A route declared as /rooms/:id matches /rooms/*, not /rooms/42.

Records that belong to no request are not filtered by path: the startup banner, store.pino and the lines runJob writes. store.pino is plain pino, so logFilter never touches it, level included. The startup banner is never filtered either. level applies to runJob lines.

Hiding the access line by path

A load balancer probing /health writes one access line per probe. accessLine hides the line for the paths you name.

logixlysia({
  config: {
    logFilter: {
      accessLine: {
        exclude: ['/health', '/metrics']
      }
    }
  }
})

include and exclude take the same globs as sampling.tail.paths. Precedence, in order:

  • An error line is never hidden, and neither is an access line whose status is 400 or above. Every other access line follows the path rules.
  • A pathname longer than 2048 characters is never hidden.
  • exclude beats include.
  • With a non-empty include, a path it does not match is hidden.
  • An empty array is the same as leaving the key out.

Only the access line is hidden. A handler’s log.* lines still write and enrichers still run. Tail sampling does not bring a hidden access line back. The option has no effect on a createLogger instance used outside the plugin.

Was this page helpful?