Unable to change netbeans logging level

It shouldn't be that hard ... change the default security level of netbeans.

Despite the fact that English is not my main language, so far I have thought that I have a good understanding of this. Every post I read says it is simple and easy to change it ... But I cannot change it. By default, my netbeans start logging in at the INFO level. I am trying to downgrade it to FINEST.

I made a small POC starting a new Java application:

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 great. "Hello!" printed in the netbeans output window. It also works for higher levels (WARNING, SEVERE).

But if I change it to FINE (or any other lower level). This did not work.

I did everything I found on the 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!"); 

-J-Djavaapplication16.level=100 netbeans.conf and added -J-Djavaapplication16.level=100 (and others). Created logging.properties at the root application level, etc. None or combined they worked.

Please, could you help me, tell me what I am doing wrong?

My environment:

 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) 

Messages I found useful but didn't work for me:

+4
source share
3 answers

I ran into the same problems ... My solution (finally) was to create a log configuration file:

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

and configure it to start the project:

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

Pay attention to the absolute path to the properties file, since I could not load it from the running class path (the checked project folder is by default, it is packed inside the package by default ... and nothing), this may have happened when you tried to download the file properties, given that several times correctly determine where the current class path is located. I relied on this topic for a solution. Netbeans version 7.2 and JDK jdk1.7.0_21.

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

You need to use strings representing levels, not their numerical equivalents. This line is copied from working code using JUL. Since then, I have found that log4j is a much better framework for logging in Java.

0
source

ConsoleHandler has a level, so I highlighted the new ConsoleHandler and set Logger and ConsoleHandler to the desired level. It 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"); } 
0
source

Source: https://habr.com/ru/post/1445779/


All Articles