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

📄 manager.java

📁 设计模式关于LOG的CLL系统
💻 JAVA
字号:
package cn.edu.nju.software.sd.cll;
import java.io.*;
import java.util.*;
public class Manager
{
	/**
	 *判断是否有父LOG
	 *如果有,则返回父LOG的配置,没有,则返回跟LOG
	 */
	public static Logger findParent(String sonName)
	{
		Logger newlog=new Logger(sonName);
		Que.que.enq(newlog);
		Que.que.sort();
		if(Que.que.head(newlog)==null)
		{
			newlog.logging.level=getRootLogger().logging.level;
			newlog.logging.logDestination=getRootLogger().logging.logDestination;
			newlog.logging.logFormat=getRootLogger().logging.logFormat;
			return newlog;
		}
		for(Object head=Que.que.head(newlog);head!=null;head=Que.que.head(head))
		{
			Logger headlog=(Logger)head;
			String parentName=headlog.logging.logName+".";
			if(sonName.indexOf(parentName)==0)
			{
				newlog.logging.level=headlog.logging.level;
				newlog.logging.logDestination=headlog.logging.logDestination;
				newlog.logging.logFormat=headlog.logging.logFormat;
				return newlog;
			}
		}
		
		newlog.logging.level=getRootLogger().logging.level;
		newlog.logging.logDestination=getRootLogger().logging.logDestination;
		newlog.logging.logFormat=getRootLogger().logging.logFormat;
		return newlog;
		
	}
	/**
	 *判断两个Logger是不是父子关系,log1是log2的父亲
	 */
	public static boolean isParent(Logger log1,Logger log2) 
	{
		String s=log1.logging.logName+".";
		if((log2.logging.logName).indexOf(s)==0)
		return true;
		else
		return false;
	}
	//是否在配置文件中
	public static boolean findit(String loggerName)
	{
		boolean findit=false;
		String line=null;
		try
		{
			BufferedReader inputStream=new BufferedReader(new FileReader("root.txt"));
			for(line=inputStream.readLine();line!=null;line=inputStream.readLine())
			{
				StringTokenizer testName=new StringTokenizer(line,"@\n");
			
				String s=testName.nextToken();
				
				if(loggerName.equals(s))
				{
					
					findit=true;
					break;
				}
			}
		
		}
		catch(FileNotFoundException e)
		{
			System.out.println("File root.txt was not found or could not be opened");
		}
		catch(IOException e)
		{
			System.out.println("Error reading from file root.txt");
		}
			return findit;
	}
	
	/**
	 *通过日志的名字查找出对应的LOG
	 *如果找到,则返回该LOG,否则返回NULL
	 */
	public static Logger findThis(String loggerName)
	{
		
		boolean findit=false;
		try
		{
			String line=null;
			BufferedReader inputStream=new BufferedReader(new FileReader("root.txt"));
			for(line=inputStream.readLine();line!=null;line=inputStream.readLine())
			{
				StringTokenizer testName=new StringTokenizer(line," @\n");
			
				String s=testName.nextToken();
				
				if(loggerName.equals(s))
				{
					
					findit=true;
					break;
				}
			}
			if(findit==true)
			{	
				Logger newLog=new Logger(loggerName);
				Que.que.enq(newLog);
				Que.que.sort();
				for(line=inputStream.readLine();line!=null;line=inputStream.readLine())
				{
				
					StringTokenizer s=new StringTokenizer(line," @");
					while(s.hasMoreTokens())
					{   
						String string=s.nextToken();
						if(string.toUpperCase().equals("LOGFORMAT"))
						{
							newLog.logging.logFormat=s.nextToken();
							newLog.logging.initFormat=true;
							break;
						}
				
						else if(string.toUpperCase().equals("LOGDESTINATION"))
						{
							newLog.logging.logDestination=s.nextToken();
							newLog.logging.initDestination=true;
							break;
						}
						else if(string.toUpperCase().equals("LOGLEVEL"))
						{
							newLog.logging.level=Level.toLevel(s.nextToken());
							newLog.logging.initLevel=true;
						}
					
					}
					if((newLog.logging.initLevel==true)&&(newLog.logging.initDestination=true)&&(newLog.logging.initFormat=true))
					break;
				}
					return newLog;
			}
		
	
			
		}
		catch(FileNotFoundException e)
		{
			System.out.println("File root.txt was not found or could not be opened");
		}
		catch(IOException e)
		{
			System.out.println("Error reading from file root.txt");
		}
		return null;
	}	
		//获取根日志
	public static Logger getRootLogger()
	{
		Logger rootLog=new Logger();
		try
		{
			BufferedReader inputStream=new BufferedReader(new FileReader("root.txt"));
			String line="null";
			
			for(line=inputStream.readLine();line!=null;line=inputStream.readLine())
			{
				
				StringTokenizer s=new StringTokenizer(line," @");
				while(s.hasMoreTokens())
				{   
				String string=s.nextToken();
					if(string.toUpperCase().equals("LOGFORMAT"))
					{
						rootLog.logging.logFormat=s.nextToken();
						rootLog.logging.initLevel=true;
						break;
					}
				
					else if(string.toUpperCase().equals("LOGDESTINATION"))
					{
						rootLog.logging.logDestination=s.nextToken();
						rootLog.logging.initDestination=true;
						break;
					}
					else if(string.toUpperCase().equals("LOGLEVEL"))
					{
						rootLog.logging.initFormat=true;
						rootLog.logging.level=Level.toLevel(s.nextToken());
					}
					
				}
					if((rootLog.logging.initLevel==true)&&(rootLog.logging.initDestination==true)&&(rootLog.logging.initFormat==true))
					return rootLog;
					
			}
		
		}
		catch(FileNotFoundException e)
		{
			System.out.println("File root.txt was not found or could not be opened");
		}
		catch(IOException e)
		{
			System.out.println("Error reading from file root.txt");
		}
		return rootLog;
	}
}

⌨️ 快捷键说明

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