fastify / under-pressure

Measure process load with automatic handling of "Service Unavailable" plugin for Fastify.
MIT License
337 stars 35 forks source link

Setting logLevel option for status route has no effect #158

Closed budarin closed 2 years ago

budarin commented 2 years ago

Prerequisites

Fastify version

3.28.0

Plugin version

5.8.1

Node.js version

18.0.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

10.‎06.‎2020

Description

.register(underPressurePligin, {
        exposeStatusRoute: {
            routeOpts: {
                logLevel: 'debug',
            },
            url: '/alive',
        },
        healthCheck: async function (fastifyInstance) {
            // do some magic to check if your db connection is healthy, etc...
            return true;
        },
    })

the contents of the log after executing the request

{
    "level": "info",
    "time": 1651439672804,
    "instance": "unknown:3000",
    "version": "1.0.0",
    "reqId": "req-1",
    "req": {
        "method": "GET",
        "url": "/alive",
        "path": "/alive",
        "parameters": {},
    },
    "msg": "incoming request"
}

log level is info instead of debug

Steps to Reproduce

setup server with under-pressure plugin with above config an run

Expected Behavior

expected loglevel for status route to be as defined in config

mcollina commented 2 years ago

The info log level is set up by Fastify itself and cannot be changed. What you can chage is the minimum log level for the healthcheck route, like so:

.register(underPressurePligin, {
        exposeStatusRoute: {
            routeOpts: {
                logLevel: 'warn',
            },
            url: '/alive',
        },
        healthCheck: async function (fastifyInstance) {
            // do some magic to check if your db connection is healthy, etc...
            return true;
        },
    })

In this way the info logs will be hidden.

budarin commented 2 years ago

I just want not to log health checks in production (when pino.logLevel is set to info) and log it in dev env (when pino.logLevel is set to trace)

mcollina commented 2 years ago

the above should do the trick

budarin commented 2 years ago

I'm sorry, but from the description in the documentation it is completely unclear how the setting of this parameter affects the display of information in the logs

climba03003 commented 2 years ago

log level always refer to the the minimum logging level which means the logging message equal or above that level will be display. If you know that all the log are in info level, setting any log level above info will disable the log showing, for example warn, error or fatal.

budarin commented 2 years ago

Thanks for the explanation!