I have an application (Java), which is depending heavily on grpc to communicate between different microservices. The problem is that in a cloud environment the calling services very often do not reach their target services. In order to resolve our issues we want to have better debugging information from grpc.
At the moment we are getting very coarse logging infos from grpc, and we would like to see logging info on the socket level (ex. "talking to socket x ...."). How can we change the logger level for grpc? Throughout the system we are using slf4j for logging purposes and our netty-logging.properties has logging-level at INFO.
What would be a good level? (we are thinking TRACE) and should we programmatically change the level with each grpc call or rather within a config file?(What would this file look like?)
gRPC Java logs output via the JDK's built-in java.util.logging
classes (searching for "java.util.logging" will turn up lots of tutorials and StackOverflow questions about configuring these log levels). The log level can be set programmatically, but typical usage is better served loading from a config file. The following sample logging.properties
would turn on verbose gRPC logging:
handlers=java.util.logging.ConsoleHandler
io.grpc.level=FINE
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
You need to provide the location of this file as a JVM flag, e.g., with the command-line flag -Djava.util.logging.config.file=logging.properties
.
You can use google-cloud-logging-logback, versions available at maven-central
<!-- add to pom.xml dependencies -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging-logback</artifactId>
<version>0.80.0-alpha</version>
</dependency>
Then turn on debug or other logging level you want in src/main/resources/logback.xml
,
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With