Sentry for logging in Spring - 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>

Related

How to troubleshoot SpringBoot app on AppEngine - Java 11 environment

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)

Java Springboot Gradle project how to write log to cloudwatch?

I have configured log4j2 in my gradle project to write the log to a local file. The log4j2.xml file is written as follow:
<Configuration>
<appender name="cloud-watch" class="io.github.dibog.AwsLogAppender">
<awsConfig>
<credentials>
<accessKeyId>XXXXX</accessKeyId>
<secretAccessKey>XXXXXX</secretAccessKey>
</credentials>
<region>us-east-2</region>
</awsConfig>
<createLogGroup>true</createLogGroup>
<queueLength>100</queueLength>
<groupName>SpringLog</groupName>
<streamName>StreamName</streamName>
<dateFormat>yyyyMMdd_HHmm</dateFormat>
<layout>
<pattern>[%thread] %-5level %logger{35} - %msg %n</pattern>
</layout>
</appender>
<Loggers>
<Root level="ALL">
<AppenderRef ref="cloud-watch"/>
</Root>
</Loggers>
</Configuration>
Here I am firstly getting an error "Unable to locate appender "cloud-watch". Also the logging to the cloudwatch is also not working.
Can any one please correct me what I am doing wrong. Your help is much appreciated. I tried consoling the log and it works fine.
Can anyone suggest on how to do logging from springboot gradle project to aws cloudwatch?
This is not a valid Log4j2 configuration. Log4j2 uses plugins and the class name of appenders, filters, layouts, etc is never specified in the configuration.
I found an example configuration similar to yours at https://github.com/dibog/cloudwatch-logback-appender. Note that the name of the project is cloudwatch-logback-appender, so this appender is designed to work with Logback, not Log4j2.

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.

logback-spring.xml loaded before spring boot application configuration properties

I have my own logback base.xml file where i define pre-defined file appenders that are used by different applications.
I want the log directory to be configurable per application with a property in application.properties (log.path) and have a default in case none is provided (/var/log), so i have:
base.xml
<included>
<property name="logPath" value="${logPath:-/var/log}"/>
<appender name="TEST" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logPath}/test.log</file>
...
</appender>
logback-spring.xml for spring boot application:
<configuration>
<springProperty scope="context" name="logPath" source="log.path" />
<include resource="base.xml" />
<root level="INFO">
<appender-ref ref="TEST"/>
</root>
</springProfile>
For some reason i end up with two log directories, both /var/log and "log.dir", it seems base.xml is interpreted before spring boot environment is ready.
I'm running spring-boot 1.5.2 comes with logback 1.1.11.
It seems the problem was caused by adding spring-cloud.
During spring cloud's boostraping process, log.dir property is not found and logback creates an logDir_IS_UNDEFINED directory. After the bootstrap process logback is re-initialized with right configuration.
Related spring-cloud issue: issue-197
See Spring Documentation, especially the section about how properties are carried over to logback. Try using logging.path as a property in your application.properties. It should be accessible as LOG_PATH in logback than.
Also the usual way to use the base file is by adding the spring-boot-starter-logging in Maven/Gradle and include it like that:
<include resource="org/springframework/boot/logging/logback/base.xml"/>
I have a similar problem. I use defaultValue. To be honest it's just a smelly workaround.
<springProperty name="configurable.canonical.name" source="canonical.name" defaultValue="${canonical_name}" />
<file>logs/${configurable.canonical.name}.log</file>
canonical_name is defined in default.properties. Maven is going to resolve it during build.

Cannot suppress debug logging of framework classes with spring boot and logback

I am working on a spring boot microservice application that uses logback for logging.
The standard logback.xml is in the default place (main/resources) and is obviously used as I can add logger-statements and they are effective.
Its content looks like this (standard apart from removed comments and the two additional logger directives):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework" level="INFO"/>
<logger name="my.app.package.MyClass" level="DEBUG"/>
</configuration>
However, even though I put this into the logback.xml file:
<logger name="org.springframework" level="INFO"/>
I get tons of debug log output from framework classes like this here:
2015-09-16 10:49:40.733 DEBUG 96549 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Rejected bean name 'contextAttributes': no URL paths identified
What is wrong with my setup? Why are framework classes not respecting my logback config?

Resources