Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grpc Logger level

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?)

like image 403
skal Avatar asked Sep 07 '25 04:09

skal


2 Answers

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.

like image 81
Eric G Avatar answered Sep 11 '25 03:09

Eric G


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> 
like image 34
prayagupa Avatar answered Sep 11 '25 01:09

prayagupa