log4j和weblogic:重复的日志消息 [英] log4j and weblogic: duplicate log messages

查看:214
本文介绍了log4j和weblogic:重复的日志消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用log4j登录我的项目。以下是它的示例设置:

I use log4j for logging in my project. Here is it's sample setup:

public class MyClass {
  private final Logger logger = Logger.getLogger(MyClass.class);

  public MyClass() {
    BasicConfigurator.configure();
    Logger.getLogger(MyClass.class).setLevel(Level.INFO);
  }

  ...

}

问题在于,在每次下一次记录器调用时,它都会复制日志消息(我的意思是在第一次呼叫时只有1条消息,在第二次呼叫时有2条相同的消息,然后有3条消息,依此类推)。似乎每次创建新记录器的实例并与所有旧实例一起使用。

如何避免这个问题?
谢谢。

The problem is that on each next logger call it duplicates log messages (I mean on first call there is only 1 message, on second call there are 2 same messages, then there are 3 of them and so on). It seems that each time new logger's instance is created and used with all old instances.
How to avoid this problem? Thanks.

UPP。试图让它静止,但它无论如何都不起作用。我仍然收到多条日志消息。有任何想法吗?可能是一些Weblogic特定的东西?

UPP. Tried to make it static,but it doesn't work anyway. I still get multiple log messages. Any ideas? Probably some Weblogic specific stuff?

推荐答案

使记录器静态

private static final Logger logger = Logger.getLogger(MyClass.class);

这里的关键是创建一个 Logger 对于每个类,而不是每个实例。

The key here is to create a Logger for each class, and not for each instance.

这篇关于log4j和weblogic:重复的日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆