How to troubleshoot SpringBoot app on AppEngine - Java 11 environment - spring-boot

My spring boot app in Google Appengine (Java 8) is failing to start
I tried java 11 model, but I cant even run that app locally to debug (one version of basic java 11 app worked, but adding more dependencies is breaking, so decided to use existing App that is Java 8 based)
./mvnw -DskipTests clean package appengine:run
appengine:run is only available for appengine-web.xml based projects
Java 8 Spring Boot:
App is not starting. I am struggling to understand what logger is used
I see this dependency
implementation
'com.google.cloud:google-cloud-logging-logback:0.121.3-alpha'
So assumed logback
my logback.xml in src\main\resources
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/cloud/gcp/autoconfigure/logging/logback-appender.xml" />
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="DEBUG">
<!-- If running in GCP, remove the CONSOLE appender otherwise logs will be duplicated. -->
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
I tried adding stackdriver and did not get it working, now I am tired, and don't want to try stackdriver. too many possibilities - https://docs.spring.io/spring-cloud-gcp/docs/current/reference/html/logging.html
(Note from website: Currently, only Logback is supported and there are 2 possibilities to log to Stackdriver via this library with Logback: via direct API calls and through JSON-formatted console logs.)
Cant debug from App Engine >> Instances . As it disappears and also shows "Resident" . No SSH ?
How can I get good debug level logs to identify the problem ? Is it memory issue or any system problem
another deployment logs - this doesn't even tell log level (except that i like info at the start)

Related

Spring Boot and Logging with External Tomcat only outputs startup log

My Spring boot 2 app is not showing any log message when is running. I can only see the startup log. This app is deployed as WAR in the production server and I configured the log to output to a file:
logging.file = app.log
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} - %msg%n
In my local I can see whatever debug message I include in my code but in the server I can't. I only see the application startup trace.
My config to generate the file is the provided by official guideance. And the tomcat dependency in the app.war:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Do you have any idea of what is happening? It is strange. The log file is generating in the server ( we deploy it in a docker container ) but after the app is running, no more log is output to the file.
By default Spring Boot logs on INFO level, which should include ERROR.
As per Spring boot logging guide 79.1.1 Configure Logback for File-only Output
If you want to disable console logging and write output only to a file, you need a custom logback-spring.xml that imports file-appender.xml but not console-appender.xml, as shown in the following example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
You also need to add logging.file to your application.properties which you have alraedy added.

Define logback shutdown hook in Spring Boot

I am using AsyncAppender in spring-boot (1.5.3.RELEASE) application.
logback.xml
<appender name="FILE_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>5000</queueSize>
<discardingThreshold>0</discardingThreshold>
<appender-ref ref="FILE" />
</appender>
As per logback documentation,
Upon application shutdown or redeploy, AsyncAppender must be stopped
in order to stop and reclaim the worker thread and to flush the
logging events from the queue.
https://logback.qos.ch/manual/appenders.html
Further it says:
In order to avoid interrupting the worker thread under these
conditions, a shutdown hook can be inserted to the JVM runtime that
stops the LoggerContext properly after JVM shutdown has been initiated
I want to know how to stop AsyncAppender in Spring Boot application. At which place in Spring Boot, should I define shutdown hook?
Just add the <shutdownHook/> instruction to your logback.xml. For example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
<appender name="FILE_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>5000</queueSize>
<discardingThreshold>0</discardingThreshold>
<appender-ref ref="FILE" />
</appender>
<!-- the rest of your logback config -->
</configuration>
With this in place you'll notice the following log message is emitted when Logback is configuring itself:
INFO in ch.qos.logback.core.joran.action.ShutdownHookAction - About to instantiate shutdown hook of type [ch.qos.logback.core.hook.DelayingShutdownHook]
I had a similar problem but with version 1.1.6 of logback and spring-boot 1.5.4.
The solution for me was to add :
logging.register-shutdown-hook=true
to the application.properties file for inviting
org.springframework.boot.logging.logback.LogbackLoggingSystem to stop the LoggerContext on ApplicationContext.close invocation.
You need not define the shutdown hook explicitly since version 1.1.10 of logback. Version 1.1.10 onwards, logback takes care of stopping the current logback-classic context (and all the appenders) when the web-app is stopped or reloaded. Try updating your logback version and check once.
Here's the updated doc: https://logback.qos.ch/manual/configuration.html#webShutdownHook

JBoss 7 EAP Application Specific Logging with Shared Modules

Maybe I am just completely missing something but I am trying to configure log4j in JBoss 7 EAP with the main goal of isloating application ( WAR ) log messages to unique files.
Our environment has Spring ( 3.X ) configured as a module, and each WAR ( let's call them WAR A and WAR B ) has its own jboss deployment descriptor for Spring as well as a log4j.xml.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="org.springframework.spring" slot="3.2" meta-inf="export" export="true" />
</dependencies>
</deployment>
</jboss-deployment-structure>
log4j.rootLogger = INFO, FILE
log4j.category.org.springframework=DEBUG
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=${jboss.server.log.dir}/webapp_a.log
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=true
log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d %-5p (%-6t) [%X{IP}] [%c] %m%n
Each application creates its own log files, however all the Spring logs are written to the JBoss server.log, and not the application specific log as I would expect. The idea is I would like to see only the spring logs that are relevant to the application in its log file
Am I missing something completely obvious, or really just not understanding how the classloading is working in JBoss 7 where this isn't even possible. Thanks
This is because you have Spring installed as a module. Modules log via the system log context which is configured via the logging subsystem.
Since the org.springframework.spring uses it's own class loader you really wouldn't want the org.springframework.spring module to log with an applications log context. The reason is any static loggers would be configured on whichever application configures the logger first.

Enabling logs in Spring boot cloud foundry application

how do i enable spring framework logs in my application. ? i have used logback.xml in my application and set the root level to debug. When i am trying to run the app locally then logs are printed but the same is not happening when i am deploying the application in CF.
The application itself is crashing due to other reason but i hoped some initial spring boot framework logging should have happened.
Below is my logback.xml file. I am not sure the console appender mentioned there will work in CF system too or not.`
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<root level="TRACE">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Best Regards,
Saurav
May be this was a problem with the spring boot CF service broker application which was causing the logs to not be printed. Check here CF Spring boot app failed to start accepting connections
But then i deleted the application and redeployed again. It started printing logs. The above configuration works.
The above Logback configuration file should work. Note: TRACE level logging will produce a lot of log messages. It might be better to turn this down to INFO. You'll need to bundle this configuration file in src\main\resources\logback.xml in your Spring Boot app structure.
Application logs in PCF must be written to stdout or stderr by your app, and you can view them in the CLI using the command cf logs. The ConsoleAppender you're using above writes to stdout, so you should be good to go.

Sentry for logging in Spring

I use Sentry (on premise) for our logging. Recently I started moving to the Spring framework, I am not able to get the logs hit Sentry servers. I tried using log4j and logger (slf4j). In both cases I was not able to make any progress. My assumption is that since I use spring-starter maven dependency, it includes logger by default, while all documentation on Sentry + Java mentions using raven. Probably my log configurations are not read because of this.
Can anybody tell me how can I get sentry working on my Spring project?
EDIT:
Here is my logback.xml which is in classpath.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="Sentry" class="net.kencochrane.raven.logback.SentryAppender">
<dsn>
http://xxx#example.com/sentry/2
</dsn>
</appender>
<root level="error">
<appender-ref ref="Sentry" />
</root>
</configuration>

Resources