Spring Boot and RESTful API(15)Logging and Custom SOLR Template

Spring Boot and RESTful API(15)Logging and Custom SOLR Template

Recently, one of our Spring Boot Project lost the logging in the CloudWatch. I was thinking it is jar conflicts because we bring in a new jar. That mades us dive into the logging for that Project for a while.

First of all, here is the MAVEN command to display the while dependencies which I really think it is useful.
>mvn dependency:tree

I used to use similar command in grails, but this is first time for maven. That is great beginning.

Here is the results how we fix that.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

That is complex because I used to directly use spring boot starter logging, right now It is kind of disable that and enable log4j2 in spring boot. But any way, since it is a quick fix. Make it working first.

In the class path, put log4j.xml there, since we streaming the logging to cloud watch, so we really do not need a File Pending or any other settings, just pending the to console

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR" shutdownHook="disable">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m\r\n%throwable{full}"/>
</Console>
<!--
<Console name="COLOR_CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m}{FATAL=red bright, ERROR=red bright, WARN=red bright, INFO=green bright, DEBUG=green bright, TRACE=blue bright}\r\n%throwable{full}"/>
</Console>
-->
<!--
<File name="FILE" fileName="${sys:java.io.tmpdir}/internal-api.log" append="true">
<PatternLayout>
<pattern>(%d{yyyy-MM-dd'T'HH:mm:ss.SXXX}) %-7p - %C %M - %m\r\n%throwable{full}</pattern>
</PatternLayout>
</File>
-->
<!--
<Async name="ASYNC_FILE" includeLocation="true">
<AppenderRef ref="FILE"/>
</Async>
-->
</Appenders>
<Loggers>
<Logger name="com.google.inject.internal" level="WARN"/>
<Logger name="com.optimaize" level="WARN"/>
<Logger name="net.sourceforge.cobertura" level="WARN"/>
<Logger name="org.hibernate" level="WARN"/>
<Logger name="com.sillycat" level="INFO" />
<Root level="ALL">
<AppenderRef ref="CONSOLE" level="INFO"/>
<!-- <AppenderRef ref="COLOR_CONSOLE" level="WARN"/> -->
<!-- <AppenderRef ref="FILE" level="ALL"/> -->
<!-- <AppenderRef ref="ASYNC_FILE" level="ALL"/> -->
</Root>
</Loggers>
</Configuration>

Another thing, we do a fix to disable the auto commit on Spring-data-solr, otherwise, our SOLR will have issue to handle 200G Data.

here is the implementation of that idea
package com.sillycat.jobsmonitorapi.repository;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.core.query.SolrDataQuery;
import org.springframework.stereotype.Repository;

@Repository
public class JobCustomRepositorySolrImpl implements JobCustomRepositorySolr
{

private final Logger logger = LoggerFactory.getLogger( this.getClass() );

@Resource
private SolrTemplate solrTemplate;

@Override
public void deleteByCampaignID( Long campaignID, Boolean commit )
{
SolrDataQuery query = new SimpleQuery( new Criteria( "campaign_id" ).is( campaignID ) );
solrTemplate.delete( "job", query );
if ( commit )
{
logger.warn( "Client side should never commit itself." );
solrTemplate.commit( "job" );
}
}

}


References:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值