How to use java logging with logging.properties

xiaoxiao2021-03-06  45

Developer Has Two Way To Let Java Use Specified Properties File To Configure Its Core Logger

Uses Use The System Property

From description of java.util.logging .logmanager -

The "java.util.logging.config.file" System Properties File (in java.util.properties Format). The Initial Logging Configuration Will Be Read from this file.

But if you try to use the system.setproperty to specify the file path, SURELY you fail

System.SetProperty ("java.util.logging.config.file", file_path;

You will Find That The Logmanager Still Use The Properties File Which Locate in

JRE / lib / logging.properties. That's Because The LogManager is initialized during VM Startup, Before Main Executes.

THE CORRECT WAY TO DO THIS SEPCIFY THE PATH USE Command

Java -djava.util.logging.config.file = configfile mainclass

When Start Up The JVM

You Can Find More Information in Google Search by this key words

System.SetProperty ("java.util.logging.config.file",

2. IF You Want to Configure this in your source code the only way is to write code as the folowing code fragment.

Logmanager manager = logmanager.getlogmanager ();

Manager.Readconfiguration (New fileInputStream (New file (file_path));

Logger.getlogger (class_name)

In this way you can let you logger work as you? Describe in your log file

Also Pls Set Handlers = java.util.logging.fileHandler, Else All your setting will not take it effect

REFERENCE:

http://www.phptr.com/articles/article.asp?p=361635&seqnum=4

转载请注明原文地址:https://www.9cbs.com/read-51539.html

New Post(0)