记录未显示 [英] Logging not showing

查看:128
本文介绍了记录未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用JUL。通常,Netbeans会打开一个输出选项卡,其中显示Tomcat并显示我生成的日志。它工作正常。但突然之间,我意识到我的日志根本没有显示,只有 System.out 被打印出来。甚至不是最高的 LOG.log(Level.SEVERE,....

I am using JUL in my application. Normally, Netbeans opens an output tab that reads "Tomcat" and shows the logs I produce. It was working fine. But suddenly, I realise that my logs are not shown at all, only the System.out get printed. Not even the higuest LOG.log(Level.SEVERE, ".....

} catch(Exception e) {
      System.out.println("This gets printed in Netbeans tab");
      LOG.log(Level.SEVERE, "This doesnt");
}

我怀疑它可能是我所包含的库,这会弄乱我的日志这有可能吗?librray可以改变我的日志显示方式吗?我怎么调查这个,因为我有点迷失了?

I suspect it can be a library I included, which is messing with my logs. Is that possible at all? Can a librray change the way my logs are shown? How can I investigate this, since I am a bit lost?

推荐答案


我怀疑它可能是我所包含的库,这会弄乱我的日志。这有可能吗?

I suspect it can be a library I included, which is messing with my logs. Is that possible at all?

是的。 JUL to SLF4J Bridge 可以删除控制台来自JUL根记录器的处理程序。一些库调用 LogManager.reset ,它可以删除和关闭所有处理程序。

Yes. The JUL to SLF4J Bridge can remove the console handler from the JUL root logger. Some libraries invoke LogManager.reset which can remove and close all handlers.


图书馆可以改变方式我的日志显示?

Can a library change the way my logs are shown?

是的。安装日志桥后,JUL记录不再由JUL格式化程序格式化。

Yes. Once the a log bridge is installed the JUL records are no longer formatted by the JUL formatters.


我如何调查此问题,因为我是有点丢失?

How can I investigate this, since I am a bit lost?

修改记录树需要权限,因此你可以安装 SecurityManager 具有所有权限,但随后使用 - Djava.security.debug =access,stack以确定调用方正在修改记录树。

Modifying the logger tree requires permissions so you can install a SecurityManager with all permissions but then turn on debug tracing with -Djava.security.debug="access,stack" to determine the caller that is modifying the logger tree.

如果这不起作用,你可以使用好的'$ code> System.out 来在加载库之前和之后打印记录器树和附加的处理程序。然后开始添加删除库,直到您看到记录器更改为止。

If that doesn't work you can use good ole' System.out to print the logger tree and the attached handlers before and after a library is loaded. Then start adding an removing libraries until you see the logger change.

import java.io.PrintStream;
import java.util.Enumeration;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class DebugLogging {

    private static final Logger log = Logger.getLogger("test");

    public static void main(String[] a) {
        log.log(Level.FINEST, "Finest");
        log.log(Level.FINER, "FINER");
        log.log(Level.FINE, "FINE");
        log.log(Level.CONFIG, "CONFIG");
        log.log(Level.INFO, "INFO");
        log.log(Level.WARNING, "WARNING");
        log.log(Level.SEVERE, "SEVERE");
        log.finest("Finest Log");
        log.finer("Finer Log");
        log.fine("Fine Log");
        log.config("Config Log");
        log.info("Info Log");
        log.warning("Warning Log");
        log.severe("Severe Log");
        printConfig(System.err);
    }

    private static void printConfig(PrintStream ps) {
        LogManager lm = LogManager.getLogManager();
        ps.append("LogManager=").println(lm.getClass().getName());
        synchronized (lm) {
            Enumeration<String> e = lm.getLoggerNames();
            while (e.hasMoreElements()) {
                Logger l = lm.getLogger(e.nextElement());
                if (l != null) {
                    print(l, ps);
                }
            }
        }
    }

    private static void print(Logger l, PrintStream ps) {
        String scn = l.getClass().getSimpleName();
        ps.append("scn=").append(scn).append(", n=").append(l.getName())
                .append(", uph=").append(String.valueOf(l.getUseParentHandlers()))
                .append(", l=").append(String.valueOf(l.getLevel()))
                .append(", fl=").println(l.getFilter());
        for (Handler h : l.getHandlers()) {
            ps.append("\t").append(l.getName()).append("->")
                    .append(h.getClass().getName()).append(", h=")
                    .append(String.valueOf(h.getLevel())).append(", fl=")
                    .append(String.valueOf(h.getFilter())).println();
        }
    }
}

这篇关于记录未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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