SWTBot中log4j的配置

How do I configure log4j to turn on logging for SWTBot?

Copy the file https://github.com/ketan/SWTBot/blob/master/org.eclipse.swtbot.swt.finder.test/src/log4j.xml to the src directory in your plugin. Ensure that the plugin's MANIFEST.MF contains the following lines, note the dependency on org.apache.log4j

Require-Bundle: org.eclipse.swtbot.go,
 org.apache.log4j
Eclipse-RegisterBuddy: org.apache.log4j

 

log4j.xml配置文件如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
	debug="false">

	<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
		<param name="Target" value="System.out" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern"
				value="%d{yyyy-MM-dd  HH:mm:ss.SSS} - %25t - %-5p - %30c{1} - (%C{1}.java:%L) - %m%n" />
		</layout>
	</appender>

	<appender name="fileAppender" class="org.apache.log4j.FileAppender">
		<param name="File" value="log/tbs_swtbot.log" />
		<param name="Append" value="false" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern"
				value="%d{yyyy-MM-dd  HH:mm:ss.SSS} - %25t - %-5p - %30c{1} - (%C{1}.java:%L) - %m%n" />
		</layout>
	</appender>

	<appender name="asyncAppender" class="org.apache.log4j.AsyncAppender">
		<!-- appender-ref ref="consoleAppender" / -->
		<appender-ref ref="fileAppender" />
	</appender>

	<!-- don't log matchers, this is very high amount of chatter -->
	<category name="org.eclipse.swtbot.swt.finder.matchers">
		<priority value="OFF" />
	</category>

	<!--
		don't log widget notification events, this is moderately high chatter
	-->
	<category name="org.eclipse.swtbot.swt.finder.widgets">
		<priority value="OFF" />
	</category>
	<category name="org.eclipse.swtbot.swt.finder.widgets">
		<priority value="OFF" />
	</category>
	<!-- don't log finders, this is moderate chatter -->
	<category name="org.eclipse.swtbot.swt.finder.finders">
		<priority value="OFF" />
	</category>

	<category name="org.eclipse.swtbot.swt.finder.keyboard">
		<!-- set to a value higher than debug to turn on. -->
		<priority value="OFF" />
	</category>

	<category name="org.eclipse.swtbot">
		<priority value="ALL" />
	</category>

	<root>
		<priority value="INFO" />
		<appender-ref ref="consoleAppender" />
		<appender-ref ref="fileAppender" />
	</root>

</log4j:configuration>

 

If you still get the message:

log4j:WARN No appenders could be found for logger (net.sf.swtbot.matcher.WidgetMatcherFactory$MenuMatcher).
log4j:WARN Please initialize the log4j system properly.

Then there's something else not right. Drop an email on the mailing list.

在根类添加log4j初始化代码:

	@BeforeClass
	public static void initSystem() throws Exception {
		DOMConfigurator.configure("./log4j.xml");//加载.xml文件
//		PropertyConfigurator.configure("./log4j.properties");
		bot = new SWTWorkbenchBot();
	}

 

你可能感兴趣的:(log4j,swtbot)