How to suppress health check logging

I’m trying to suppress logging of a health check endpoint in my Phoenix Application. I managed to switch off logging in controller with
use Phoenix.Controller, namespace: DsrvWeb, log: false

but I can still see messages related to health checking

20:02 $ mix phx.server
[info] Running DsrvWeb.Endpoint with Cowboy using http://0.0.0.0:4000
[info] GET /health_check
[info] Sent 200 in 11ms

How can I get rid of these messages. Of course, I want other routes to be logged as usual.

4 Likes

You might consider using a separate router / endpoint for this path. You can also move the Plug.Logger or whatever it is called into a separate pipeline within your router, which isn’t used for the health check route.

1 Like

Just stumbled across this article which uses a plug to avoid logging

4 Likes

Unfortunately passing log: false to the scope doesn’t seem to be working to silence the info level messages that get printed. I can pass log: :debug and that changes it to debug level, but false doesn’t disable them. Phoenix 1.5.8

I actually wrote a library to solve this exact problem: unplug | Hex

The main use case for the library was to conditionally execute plugs while preserving the init_mode behavior of a plug definition. For example, if you wanted to omit the Telemetry plug from a request pipeline, you would do the following:

plug Unplug,
    if: {Unplug.Predicates.RequestPathNotIn, ["/metrics", "/healthcheck"]},
    do: Plug.Telemetry

Source: GitHub - akoutmos/unplug: Unplug allows you to conditionally execute your Elixir plugs at run-time

2 Likes