在java logger的配置文件中指定自己的Formatter

发布于 2024-08-20 15:36:38 字数 468 浏览 3 评论 0原文

我通过扩展类java.util.logging.Formatter编写了一个Formatter (test.MyFormatter);

现在我想使用 test.MyFormatter 而不是 java.util.logging.SimpleFormatter:

在配置文件中我替换了条目:

java.util.logging。 ConsoleHandler.formatter = java.util.logging.SimpleFormatter

java.util.logging.ConsoleHandler.formatter = test.MyFormatter

不幸的是,这不起作用。

有人可以解释我吗,如果我正在做的是:

  1. 正确
  2. 的话,为什么它不起作用?

I wrote a Formatter (test.MyFormatter) by extending the class java.util.logging.Formatter;

Now I want to use test.MyFormatter instead of java.util.logging.SimpleFormatter:

in the configuration file i replaced the entry:

java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

with

java.util.logging.ConsoleHandler.formatter = test.MyFormatter

unfortunately this is not working.

can somebody explain me, if what I am doing is:

  1. correct
  2. if yes, why it not working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪失控 2024-08-27 15:36:38

根据 javadoc您的配置是正确的。

如果它不起作用,请仔细检查

  1. test.MyFormatter 是否在您的类中
    路径
  2. 检查您是否无意中使用了 Log4J 或 Commons-logging。
  3. 检查您的配置是否已加载。
  4. 检查您的 MyFormatter 是否具有不带参数的公共构造函数。

According to the javadoc your configuration is correct.

If it is not working double check that

  1. test.MyFormatter is in your class
    path
  2. Check that you don't accidentally use Log4J or Commons-logging.
  3. Check that your configuration is loaded.
  4. Check that your MyFormatter has public constructor without parameters.
山有枢 2024-08-27 15:36:38

您必须使用 LogManager 类。像这样的事情:

LogManager.getLogManager().readConfiguration(
      getClass().getResourceAsStream("path/to/logging.xml");

You have to override the default configuration using the LogManager class. Something like this:

LogManager.getLogManager().readConfiguration(
      getClass().getResourceAsStream("path/to/logging.xml");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文