slf4j

Initialize slf4j with log4j2.xml

不羁的心 提交于 2021-02-08 09:24:06
问题 I want to use slf4j over log4j. I added the following dependencies in my pom.xml (I used 1.7.25 for slf4j and 2.10.0 for log4j2): <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j

Velocity upgrade from 1.7 to 2.0

半腔热情 提交于 2021-02-08 06:38:33
问题 I am trying to migrate from velocity 1.7 where I use LogChute interface. In my current implementation I have used the log method to get the velocity log level and comparing our own log level. Please see the code below. @Override public void log(int level, String message) { LogLevel projLevel = null; switch ( level ) { case LogChute.DEBUG_ID: projLevel = LogLevel.DEBUG ; break ; case LogChute.INFO_ID: projLevel = LogLevel.INFO ; break ; case LogChute.WARN_ID: projLevel = LogLevel.WARNING ;

SLFJ4 bridge for the Maven logger

余生长醉 提交于 2021-02-08 05:36:38
问题 I'm writing a Maven 3.x plugin and want to log with SLF4J & Logback. I found some SLF4J bindings for the Maven Logger: http://www.jcabi.com/jcabi-maven-slf4j/index.html https://bitbucket.org/peachjean/slf4j-mojo However, these seem to be SLF4J bindings but I believe what I need is a bridge for the Maven Logger i.e. to bridge/route all Maven log statements to SLF4J and use LogBack binding with logback.xml config. 回答1: You can use SLF4J directly from Maven plugin since Maven 3.1: The standard

Double log files in spring boot application

十年热恋 提交于 2021-02-07 14:18:28
问题 I have a spring boot application, called service1, which uses the following hierarchy of property files to configure the logs: bootstrap.yml has: spring.application.name = service1 application.yml has: logging.file: /app/logs/${spring.application.name}.log logging.level.root: INFO logging.level.com.myproject.api: TRACE The log framework used is Slf4j, which is injected into every class by using Lombok's @Sfl4j annotation. spring boot claims to have default support for this, which it does, but

Double log files in spring boot application

邮差的信 提交于 2021-02-07 14:18:26
问题 I have a spring boot application, called service1, which uses the following hierarchy of property files to configure the logs: bootstrap.yml has: spring.application.name = service1 application.yml has: logging.file: /app/logs/${spring.application.name}.log logging.level.root: INFO logging.level.com.myproject.api: TRACE The log framework used is Slf4j, which is injected into every class by using Lombok's @Sfl4j annotation. spring boot claims to have default support for this, which it does, but

Get a dummy slf4j logger?

南楼画角 提交于 2021-02-07 12:27:25
问题 Can I get a dummy logger from slf4j? (Think the null object design pattern.) If so, can someone provide an example? Or will I have to implement a custom logger if I want to do that? I'm hoping to write a function along the lines of private Logger logger; static Logger nullLogger; static { nullLogger = getMeADummyLogger(); } public Logger getLogger() { return this.logger == null ? nullLogger : this.logger; } // then, elsewhere: this.getLogger().info("something just happened"); and not get a

IDEA maven项目查自动查看依赖关系,解决包冲突问题

允我心安 提交于 2021-02-05 03:07:37
<div id="content_views" class="markdown_views"> <!-- flowchart 箭头图标 勿删 --> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path> </svg> <p>在maven项目中找到pom.xml,打开。</p> <pre class="prettyprint" name="code"><code class="hljs xml has-numbering" onclick="mdcp.signin(event)"> <span class="hljs-tag"><span class="hljs-tag"><</span><span class="hljs-title"><span class="hljs-tag"><span class="hljs-name">dependencies</span></span></span><span class="hljs-tag">

Java异步多线程编程探索之CompletableFuture

我的未来我决定 提交于 2021-02-04 08:53:45
  CompletableFuture是JDK1.8新增的一个异步执行任务类,可以发挥多核CPU的优势,也可以将任务并行执行,最后归并结果,下面是一个工具类,这个工具类使用在遍历集合处理数据或调用接口时,异步执行任务,最后归并任务,提升执行性能,具体代码如下。 import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.function.BiFunction; import java.util.function.Function; /** * 异步执行工具类 继承 CompletableFuture * @author yangchangkui */ public class AsyncUtil extends CompletableFuture { private static final Logger

Feign自定义异常处理

百般思念 提交于 2021-01-31 05:30:16
问题 FeignClient接口调用异常时,默认会在接口原始异常信息基础上包装一层Feign Request信息: code: -1 message: "[401 ] during [POST] to [http://uaa-center-server/oauth/token?grant_type=pin_code&username=sujingjun%40dhgate.com&password=liangb1231aaa&userType=1&verificationCode=0ee3674f07a7e3c7c3d87b4fb779afe3dq] [UaaServerClient#postAccessToken(String,String,String,Integer,String)]: [{"success":false,"code":401,"message":"username or password error."}]" success: false 业务系统无法通过异常类的不能直接在异常信息中看出原始方法抛出的异常,需要做异常字符串截取等处理。Feign封装过的异常,不能直接在异常信息中看出原始方法抛出的异常。当调用服务时,如果服务返回的状态码不是200,就会进入到Feign的ErrorDecoder中,因此如果我们要解析异常信息,就要重写ErrorDecoder:

服务网关ZuulFilter过滤器--pre/post/error的用法(校验请求信息,获取路由后的请求/响应信息,处理服务网关异常)

 ̄綄美尐妖づ 提交于 2021-01-30 07:18:09
微服务中Zuul服务网关一共定义了四种类型的过滤器: pre:在请求被路由(转发)之前调用 route:在路由(请求)转发时被调用 error:服务网关发生异常时被调用 post:在路由(转发)请求后调用 我在项目中用到了,pre/error/post三种类型,先记录一下 pre过滤器主要是用来校验各种信息的 import com.alibaba.fastjson.JSONObject; import com.dkjk.gateway.context.ResponseBean; import com.dkjk.gateway.domain.DockCompanyService; import com.dkjk.gateway.domain.UserService; import com.netflix.zuul.ZuulFilter; import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.exception.ZuulException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component;