0

I have a Spring boot application deployed to GCP App Engine with logback as a logging framework. The problem which I am facing is that I can not find the logger messages which I put into my code. I found a similar post: Google App Engine - Can not find my logging messages. But it is pretty much older and the solutions are not working anymore. On this post, it is mentioned to set the logger level manually. On a similar line, I used logging.properties file to set the level as INFO. But still, it was of no use.

I thought the issue might be with the file permission on the App Engine. So, I specified the log file location at /tmp having full read-write permissions. It did not work. If there are any exception scenarios then stack traces are visible on Stackdriver Logging. Please suggest.

Swapnil
  • 801
  • 3
  • 19
  • 42

1 Answers1

0

Here is how I managed to make the logs appear in Stackdriver under java.log.

I created a file myApp/src/main/resources/logback.xml and added this configuration:

<configuration>
  <appender name="STDOUT" class="com.google.cloud.logging.logback.LoggingAppender">
  </appender>

  <root level="info">
          <appender-ref ref="STDOUT"/>    
  </root>
</configuration>

I also added the dependency in the file myApp/pom.xml :

<dependencies>

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-logging-logback</artifactId>
      <version>0.80.0-alpha</version>
    </dependency>

    <!-- other dependencies -->

</dependencies>

Then in my main.java I did logger.info("my info log") and logger.error("my error log") and the logs appeared in Stackdriver after a few seconds of accessing my web app.

I took the sample code from the GoogleCloudPlatform/getting-started-java repository to deploy my app.

TasosZG
  • 1,274
  • 1
  • 6
  • 13
  • That seems to be the perfect solution! Based on your input, I referred https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/logging/logback which mentions how to specify the log file name. But still, the problem is I am not sure where to find the log file. Can you suggest me on this? – Swapnil Feb 12 '19 at 05:10
  • 1
    Sure :) From the Google Cloud Platform Console you to Stackdriver Logging, you select in the first dropdown menu GAE Application -> and in the second dropdown menu you select "java.log". Note that this choice will only appear if you have already logged messages and if you don't change the default choice in the tag in the appender (which is "java.log"). – TasosZG Feb 12 '19 at 08:03
  • That's the perfect solution! Thanks for helping me! :) – Swapnil Feb 12 '19 at 17:45