FINE,FINER,FINEST

D

Daniel Parker

On Windows XP, JDK 1.4.2_06, I'm getting the following results:

Logger logger = Logger.getLogger(this.getClass().getName(),null);

logger.setLevel(Level.INFO);
logger.getLevel() -> returns INFO
logger.info(message); -> prints message

logger.setLevel(Level.FINE);
logger.getLevel() -> returns FINE
logger.fine(message); -> doesn't print anything

logger.setLevel(Level.FINER);
logger.getLevel() -> returns FINER
logger.fine(message); -> doesn't print anything

logger.setLevel(Level.ALL);
logger.getLevel() -> returns ALL
logger.fine(message); -> doesn't print anything

Basically, SEVERE, WARNING, and INFO work as expected, but FINE, FINER and
FINEST don't seem to work at all. Does anyone have any idea what is going
on? I couldn't find anything with google.

Regards,
Daniel Parker
 
F

Filip Larsen

Daniel Parker wrote
Basically, SEVERE, WARNING, and INFO work as expected, but FINE, FINER and
FINEST don't seem to work at all. Does anyone have any idea what is going
on? I couldn't find anything with google.

You need to set the level on each Handler you want to deliver the log
record. In this case you probably want to set the level on the
ConsoleHandler, which per default is set to print only INFO and above.
Edit your <JRE Home>/lib/logging.properties file to set it differently
is one way to do it.

Since the logging system is rather flexible I recommend that you visit
http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html if you
haven't already.


Regards,
 
S

Simor

Filip Larsen said:
Daniel Parker wrote


You need to set the level on each Handler you want to deliver the log
record. In this case you probably want to set the level on the
ConsoleHandler, which per default is set to print only INFO and above.
Edit your <JRE Home>/lib/logging.properties file to set it differently
is one way to do it.

Since the logging system is rather flexible I recommend that you visit
http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html if you
haven't already.
Hi,
it's seams you know about the java logging api. Maybe you can help me
,too?

I don't want to use the default configuration from
/lib/logging.properties. So i set java property
"java.util.logging.config.file" like this:
System.setProperty("java.util.logging.config.file",System.getProperty("user.dir")
+ System.getProperty("file.seperator") + "customproperties");

I got no erromsg, but changes in the file, doesn't have any effect on
the applications logging behavior.

If i manipulate the /lib/logging.properties file, of course it works,
but i doen't want change the configuration global for all project. I
only want it for one special project!

THX
 
S

Simor

Filip Larsen said:
You need to set the level on each Handler you want to deliver the log
record. In this case you probably want to set the level on the
ConsoleHandler, which per default is set to print only INFO and above.
Edit your <JRE Home>/lib/logging.properties file to set it differently
is one way to do it.

Since the logging system is rather flexible I recommend that you visit
http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html if you
haven't already.


Regards,

Hi,
it's seams you know about the java logging api. Maybe you can help me
,too?

I don't want to use the default configuration from
/lib/logging.properties. So i set java property
"java.util.logging.config.file" like this:
System.setProperty("java.util.logging.config.file",System.getProperty("user.dir")
+ System.getProperty("file.seperator") + "customproperties");

I got no erromsg, but changes in the file, doesn't have any effect on
the applications logging behavior.

If i manipulate the /lib/logging.properties file, of course it works,
but i doen't want change the configuration global for all project. I
only want it for one special project!

THX
 
D

Daniel Parker

Filip Larsen said:
You need to set the level on each Handler you want to deliver the log
record. In this case you probably want to set the level on the
ConsoleHandler, which per default is set to print only INFO and above.
Edit your <JRE Home>/lib/logging.properties file to set it differently
is one way to do it.

Since the logging system is rather flexible I recommend that you visit
http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html if you
haven't already.
Thanks, I appreciate the pointers.

Daniel
 
F

Filip Larsen

Simor wrote
I don't want to use the default configuration from
/lib/logging.properties. So i set java property
"java.util.logging.config.file" like this:
System.setProperty("java.util.logging.config.file",System.getProperty("u
ser.dir")
+ System.getProperty("file.seperator") + "customproperties");

I got no erromsg, but changes in the file, doesn't have any effect on
the applications logging behavior.

My guess would be that either you set the system property after
LogManager has initialized (try use -D option on the command line to
define the property early), or the file you specify is not there (try
use a fixed filename and make sure that you include the extension).


Regards,
 
Joined
Aug 26, 2009
Messages
1
Reaction score
0
Its finally Working, below is the code

I tried with with many possible combination and the code finally worked with passing the argument as

java -Djava.util.logging.config.file=logging.properties LoggerTest

Code:
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.ConsoleHandler;

public class LoggerTest {
	
	private static Logger theLogger =  Logger.getLogger(LoggerTest.class.getName());
	
	public static void main(String[] args) throws Exception{

		System.out.println("sys prop:" + System.getProperty("java.util.logging.config.file"));
		System.out.println("Current Logger level:" + theLogger.getLevel()); // I still dont know why its null
		System.out.println("Current Resource Bundle Name:" + theLogger.getResourceBundle());
			
		theLogger.log(Level.SEVERE, "I AM SEVERE"); 
		theLogger.log(Level.WARNING , "I AM WARNING"); 
		theLogger.log(Level.INFO , "I AM INFO "); 
		theLogger.log(Level.CONFIG , "I AM CONFIG ");
		theLogger.log(Level.FINE , "I AM FINE");
		theLogger.log(Level.FINER , "I AM FINER ");
		theLogger.log(Level.FINEST , "I AM FINEST ");
		
	}
}


The properties files is :
Code:
handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=FINEST
.level = FINER

change .level property to SEVERE/INFO/FINER etc and see the difference..
This '.level' property is very important even you have specified the level of ConsoleHandeler ..

but i still have a doubt : "Current Logger level" on line 12 in java code is showing null...may be if we specify the pakage level logging in configuration file, it will show up..

Hope this helps
Naveen
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top