简体   繁体   English

不可能更改Netbeans日志记录级别

[英]Impossible to change netbeans logging level

This shouldn't be so complicated... change netbeans default logging level. 这应该没有那么复杂...更改netbeans的默认日志记录级别。

Despite the fact that english isn't my primary language, until now, I thought that I had a good understanding of it. 尽管英语不是我的主要语言,但直到现在,我仍然认为自己对此有很好的理解。 Every post that I read states that is simple and easy to change it... But I can't manage to change it. 我读过的每篇文章都指出,更改很简单,却很容易...但是我无法更改它。 By default, my netbeans starts logging at INFO level. 默认情况下,我的netbeans在INFO级别开始记录。 I'm trying to lower it to FINEST. 我正在尝试将其降低到最佳状态。

I did a small POC, starting a brand new java application: 我做了一个小的POC,启动了一个全新的Java应用程序:

package javaapplication16;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public class JavaApplication16 {

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

    public static void main(String[] args) {        
        logger.log(Level.INFO, "hello!");
    }
}

It works fine. 工作正常。 "hello!" “你好!” is printed in netbeans output window. 在netbeans输出窗口中打印。 It also works for higher levels (WARNING, SEVERE). 它也适用于更高级别(警告,严重)。

But if I change it to FINE (or any other lower level). 但是,如果我将其更改为FINE(或其他任何较低级别)。 It didn't work. 没用

I did everything that that I found on internet. 我做了在互联网上找到的所有内容。

I changed main to 我将主要更改为

System.setProperty("javaapplication16.level", "100");
System.setProperty("javaapplication16.JavaApplication16", "100");
System.setProperty("java.util.logging.ConsoleHandler.level", "100");
try {
    LogManager.getLogManager().readConfiguration();
} catch (IOException | SecurityException ex) {
    logger.log(Level.SEVERE, null, ex);
}

logger.log(Level.FINE, "hello!");

Changed netbeans.conf and added -J-Djavaapplication16.level=100 (and others). 更改了netbeans.conf并添加了-J-Djavaapplication16.level=100 (及其他)。 Created a logging.properties at app root level, etc... Neither alone or combined they worked. 在应用程序根级别等创建了logging.properties

Please, could you help me, point me out what I'm doing wrong? 拜托,你能帮我,指出我做错了什么吗?

My environment is: 我的环境是:

Product Version: NetBeans IDE 7.2 (Build 201207171143)
Java: 1.7.0_07; Java HotSpot(TM) 64-Bit Server VM 23.3-b01
System: Mac OS X version 10.8.2 running on x86_64; US-ASCII; en_US (nb)

Posts that I found useful, but didn't worked for me: 我发现有用但对我无效的帖子:

I ran into the same problems... My solution (finally) was to create a logging config file: 我遇到了同样的问题...我的解决方案(最终)是创建一个日志记录配置文件:

handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL

and set it up to the project running options: 并将其设置为项目运行选项:

>Project
>Properties
>Run
>VM Options: -Djava.util.logging.config.file=/home/myuser/logging.properties

Note the absolute path to the properties file, since I was not able to not load it from the running classpath (tried default project folder, default packaged, inside a package... and nothing), maybe that was happening when you were trying to load the properties file, given it's difficult some times to correctly determine where is located the current classpath. 注意属性文件的绝对路径,因为我无法从正在运行的类路径中加载它(尝试了默认项目文件夹,默认打包,在包内...什么也没有),这可能是在您尝试执行此操作时发生的加载属性文件,因为有时很难正确确定当前类路径的位置。 I based myself on this thread for the solution. 我基于此线程寻求解决方案。 Netbeans version 7.2 and JDK jdk1.7.0_21. Netbeans 7.2版和JDK jdk1.7.0_21。

 System.setProperty("java.util.logging.ConsoleHandler.level", "FINER");

You need to use the strings representing the levels, rather than their numeric equivalents. 您需要使用代表级别的字符串,而不是等同的数字。 That line is copy-pasted from working code using JUL. 该行是使用JUL从工作代码复制粘贴的。 I've since found that log4j is a far better framework for logging in Java. 从那以后,我发现log4j是Java中更好的日志记录框架。

The ConsoleHandler has a level also so I allocated a new ConsoleHandler and set both the Logger and ConsoleHandler to the desired level. ConsoleHandler也具有一个级别,因此我分配了一个新的ConsoleHandler并将Logger和ConsoleHandler都设置为所需的级别。 That worked! 可行!

    private static final Logger myLogger=Logger.getLogger(OrderApiClientJersey2_51_1.class.getName());
    static
    {
        // Default consoleHandler and Logger only log at INFO level
        Handler consoleHandler = new ConsoleHandler();  
        consoleHandler.setLevel(Level.ALL);
        myLogger.setLevel(Level.ALL);
        myLogger.addHandler(consoleHandler);
        myLogger.log(Level.FINEST, "Test Output");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM