小编Set*_*etu的帖子

如何自定义log4j2 RollingFileAppender?

我们使用log4j 1.2.x登录我们的产品,并希望在不久的将来迁移到log4j 2.x. 我们实现的功能之一是在生成的每个新的翻转日志文件上记录系统信息和其他重要参数.我们在log4j 1.2.x中实现的方式是我们有扩展RollingFileAppender的log4j类并覆盖了rollOver()方法,下面是实现的部分片段

@Override
public void rollOver() {

    super.rollOver(); //We are not modifying it's default functionality but as soon as rollOver happens we apply our logic 

    // 
    // Logic to log required system properties and important parameters.
    //

}
Run Code Online (Sandbox Code Playgroud)

现在我们想要迁移到log4j2,我们正在寻找一种新的解决方案来实现相同的功能.但是当我看到log4j2的源代码时,它与旧的源代码非常不同.本RollingFileAppender类不包含rollover(),因为它已经被移动到方法RollingManagerhelper,它已经被设置为private为井.

开发一个完整的新包并从log4j2扩展/实现一些抽象/辅助类是我们可能的解决方案之一,但这需要大量编码/复制,因为我们不修改什么RollingFileAppender,而只需要对它进行小扩展.有一个简单的解决方案吗?

UPDATE

我根据答案中的建议创建了自定义查找,下面是我创建它的方式;

@Plugin(name = "property", category = StrLookup.CATEGORY)
public class CustomLookup extends AbstractLookup {

private static AtomicLong aLong = new AtomicLong(0);

@Override
public …
Run Code Online (Sandbox Code Playgroud)

java logging log4j log4j2

6
推荐指数
1
解决办法
5318
查看次数

对于不存在的测试套件,AssertionFailedError Forked Java VM 异常退出

这可能看起来与 SO 上的某些内容重复,但是我已经查看了this、this、this和this但还没有找到有效的解决方案。

我遇到的问题是我在 jenkins 上为非现有测试套件收到此错误。以下是 jenkins ant 构建日志中打印的错误;

compile-tests-run:
    [junit] Testsuite: com.smartstream.control.engine.validation.Batch-With-Multiple-Tests
    [junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
    [junit] 
    [junit] Testcase: null took 0 sec
    [junit]     Caused an ERROR
    [junit] Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.
    [junit] junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in …
Run Code Online (Sandbox Code Playgroud)

java ant junit jenkins

4
推荐指数
1
解决办法
3484
查看次数

@Size 和 @Pattern 注释在 Spring MVC 中不起作用

将以下 jar 添加到我的 WEB-INF 中的 lib 文件夹中:

  • 同学-1.0.0
  • javax.el-2.2.4
  • javax.el-api-2.2.4
  • jboss-logging-3.1.3.GA
  • 验证-api-1.1.0.Final

我添加的代码片段是:

从模型对象:

public class UserDetails {

    @Pattern(regexp="(^0-9}*") 
    private String userName;   

    @Size(min=2,max=10)
    private String firstName;    
    private String lastName;
    private String emailId;
    private ArrayList<String> accountType;
    private ArrayList<String> gender;

    @Size(min=2,max=10)
    private Long accountNo;
Run Code Online (Sandbox Code Playgroud)

FromController 类:

@RequestMapping(value = "/UserAccount.html", method = RequestMethod.POST)
public ModelAndView userAccountForm(
        @Valid @ModelAttribute("user") UserDetails user,
        BindingResult result) {

    if (result.hasErrors()) {
        ModelAndView model1 = new ModelAndView("LoginForm");
        return model1;
    }

    ModelAndView model1 = new ModelAndView("UserAccount");
    return model1;
}
Run Code Online (Sandbox Code Playgroud)

我的调度程序 …

spring spring-mvc

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×2

ant ×1

jenkins ×1

junit ×1

log4j ×1

log4j2 ×1

logging ×1

spring ×1

spring-mvc ×1