SLF4J 在信息级别记录错误消息

发布于 2024-12-28 15:38:19 字数 595 浏览 3 评论 0原文

我遇到了一个奇怪的问题。我有一个曾经使用 Log4j 的类,我可以执行以下操作:

LOGGER.log(Level.SEVERE, "This is a message");

我会得到如下输出:

严重:这是一条消息

我将其替换为 SLF4J 记录器,以便与应用程序的其余部分保持一致:

LOGGER.error("This is a message.");

但现在它在 INFO 级别记录:

信息:2012-01-23 16:50:43,306 [http-thread-pool-8080(3)] 错误 com.mycompany.MyClass - 这是一条消息

我希望将其记录在错误级别(SLF4J 不会似乎有任何高于此的水平)。

知道发生了什么事吗?这是默认设置吗?该应用程序相当复杂,因此如果在某个地方进行了更改,我不会感到惊讶,但是我在哪里可以找到将其更改回来的内容?

我正在使用 Glassfish,以防可能相关。

I'm running into a weird problem. I have a class that used to use Log4j, and I could do something like:

LOGGER.log(Level.SEVERE, "This is a message");

And I'd get output like this:

SEVERE: This is a message

I replaced it with an SLF4J logger for consistency with the rest of the application:

LOGGER.error("This is a message.");

But now it's logging at INFO level:

INFO: 2012-01-23 16:50:43,306 [http-thread-pool-8080(3)] ERROR com.mycompany.MyClass - This is a message

I was expecting this to be logged at ERROR level (SLF4J doesn't seem to have any levels above that).

Any idea what's going on? Is this the default? The application is fairly complicated, so I wouldn't be surprised if this was changed somewhere, but where would I find that to change it back?

I'm using Glassfish, in case that might be related.

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

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

发布评论

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

评论(2

路弥 2025-01-04 15:38:19

你需要让你的 SLF4J 使用 Java Util Logging 后端。这就是 Glassfish 内部使用的。因为它没有使用它,所以它转储到控制台,并且 GF 将控制台上的所有内容报告为 INFO。

因此,连接 JUL 适配器就可以了。

you need to make your SLF4J use the Java Util Logging backend. That's what Glassfish uses internally. Since it's not using that, it's dumping to the console, and GF reports everything on the console as INFO.

So hook up the JUL adapter and you should be all good.

野味少女 2025-01-04 15:38:19

没有用于记录的配置列表,这只是一个猜测。但我认为日志框架可能配置错误。 slf4j 在 ERROR 级别记录:

ERROR com.mycompany.MyClass - This is a message

然后此输出被发送到控制台,该控制台由 glassfish 重定向到 INFO 级别的常规日志文件。

之前的设置可能使用 glassfish 日志记录直接继承其配置。切换到 slf4j 后找不到配置,因此所有内容都会发送到控制台,然后发送到 server.log

without configuration listing for logging it's only a guess. but I think the logging framework is probably misconfigured. slf4j logs at ERROR level:

ERROR com.mycompany.MyClass - This is a message

then this output is sent into console, which is redirected into general log file at INFO level by glassfish.

previous setup probably used glassfish logging directly inheriting its configuration. after switching to slf4j no config was found so everything is sent to console and then to server.log

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