How to use java logging with logging.properties

原创 2005年03月02日 22:26:00

Developer has two way to let java use specified properties file to configure its core Logger

1. Use the system property

From description of  java.util.logging .LogManager --

       the "java.util.logging.config.file" system property can be used to specify a 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 is 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 following 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 effect

Reference:

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

相关文章推荐

How To Turn Up Logging on the Siebel Web Server Extension in Siebel Versions 7.x and 8.x? [ID 477185

How To Turn Up Logging on the Siebel Web Server Extension in Siebel Versions 7.x and 8.x? [ID 477185...

Re: How to use values of properties file in selenium code - msg#02103

Great points Mark, thanks. That will be a good reasoning of disadvantages to the approach. Also w...
  • aerchi
  • aerchi
  • 2012年10月18日 10:39
  • 1932

How can I use Microsoft Visual C++ 2010 to create MEX files with MATLAB 7.10 (R2010a)?

直接下载下面的压缩包,然后解压出来,把\bin\win32\mexopts里面对应的文件拷贝到matlab2010a安装路径里面对应的文件夹下面即可!!   I have Visual Studi...

How To Use Box2D For Just Collision Detection with Cocos2D iPhone

How To Use Box2D For Just Collision Detection with Cocos2D iPhoneLike this post? Follow me on Twitte...

【OpenCV】How to Use Tesseract with C++ or OpenCV

说明:在使用Tesseract 之前,一定要安装好Tesseract ,并在Project中配置好Tesseract 路径。 1. Tesseract 在C++中直接使用// tess.cpp: /...

How to use json with as3corelib in flex( JSON )

How to use json with as3corelib in flex(  JSON ) 摘要:本文主要介绍as3corelib如何在flex中使用,以及如何在flex中使用json...

How To Use Box2D For Just Collision Detection with cocos2d-iphone

原文地址:http://www.raywenderlich.com/606/box2d-tutorial-for-ios-how-to-use-box2d-for-just-collision-det...
  • cubesky
  • cubesky
  • 2014年08月22日 11:52
  • 877

How to use iPhone with File I/O Functions: A Tutorial for Software Developers

转自:http://servin.com/iphone/iPhone-File-IO.html Introduction The iPhone OS, like Mac OS X,...

如何在MMIT上使用WMLScript文件(How To Use WMLScript Files With MMIT)

准备翻译原文:http://www.dotnet247.com/247reference/msgs/20/103177.aspx++++++++++++++++++++++++++++++++++++...

How To Use MySQL with Your Ruby on Rails Application on Ubuntu 14.04

Introduction Ruby on Rails uses sqlite3 as its default database, which works great in many cases, b...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to use java logging with logging.properties
举报原因:
原因补充:

(最多只允许输入30个字)