⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logsynch.java

📁 中国移动定位引擎的客户端
💻 JAVA
字号:
package ffcs.logging;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;

import javax.xml.parsers.FactoryConfigurationError;

public class LogSynch extends Thread{
	
	boolean running =true;
	File logFile = null;
	long cfgLastModified=System.currentTimeMillis();
	
	public LogSynch(){
		super("LogSynch");
		super.setDaemon(true);
		ClassLoader cl = this.getClass().getClassLoader();
	    URL fileUrl = cl.getResource("log4j.xml");
	    try{
	    	logFile = new File(URLDecoder.decode(fileUrl.getPath(),System.getProperty("file.encoding")));
	    }catch(UnsupportedEncodingException uee){
	    	uee.printStackTrace();
	    	logFile = new File(fileUrl.getPath());
	    }
	    
	  }
	
	public void stopThread(){
		running=false;
	}
	
	public void updateLogConfig() throws MalformedURLException, FactoryConfigurationError{
		long newTime = logFile.lastModified();
	    if(newTime==0 || cfgLastModified == 0){
	    	System.err.println(logFile + " file does not exist!");
	    }else if(newTime>this.cfgLastModified){
			resetConfig();
		}
	    this.cfgLastModified = newTime;
	}
	
	public void resetConfig() throws MalformedURLException, FactoryConfigurationError{
		org.apache.log4j.LogManager.resetConfiguration(); 
		org.apache.log4j.xml.DOMConfigurator.configure(logFile.toURL());
	}
	
	public void run(){
		while(running){
			try{
				Thread.sleep(60000);
				updateLogConfig();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -