grpc-java

Suppressing Netty exceptions from inside gRPC


gRPC Java uses Netty for HTTP/2 under the hood. If you send a HTTP/1 request, then Netty's HTTP/2 handler will throw an exception, which is printed to the logs by gRPC as follows:

Apr 09, 2024 12:47:17 PM io.grpc.netty.NettyServerTransport notifyTerminated INFO: Transport failed io.netty.handler.codec.http2.Http2Exception: Unexpected HTTP/1.x request: GET / at ...

Basically, this is all trash from people scanning my service and I would like suppress these.

My application uses SLF4J and I currently sets the log level on the command line as follows:

-Dorg.slf4j.simpleLogger.defaultLogLevel=warn -Dorg.slf4j.simpleLogger.log.com.foo.bar=info

It looks like gRPC and the shaded Netty library does not respect the log level set here. Any ideas how to suppress INFO level logging from Netty within gRPC?


Solution

  • gRRPC-Java uses standard Java logging where logging levels are managed by the LogManager. You can control what gets logged programmatically or with a config file that you point to with the java.util.logging.config.file system property.

    E.g to control the NettyServerTransport I think this would give you what you need.

    handlers = java.util.logging.ConsoleHandler
    java.util.logging.ConsoleHandler.level = ALL
    
    io.grpc.netty.NettyServerTransport.level = WARNING
    

    I am not sure how this interacts with slf4j though.