@Test
public void testConfigDirLog4jConfig() throws IOException {
RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
File configDir = new File("target", UUID.randomUUID().toString());
Assert.assertTrue(configDir.mkdirs());
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("log4j.properties");
OutputStream os = new FileOutputStream(new File(configDir, "log4j.properties"));
IOUtils.copy(is, os);
is.close();
os.close();
Mockito.when(runtimeInfo.getConfigDir()).thenReturn(configDir.getAbsolutePath());
Mockito.when(runtimeInfo.getLog4jPropertiesFileName()).thenReturn("log4j.properties");
new LogConfigurator(runtimeInfo).configure();
Mockito.verify(runtimeInfo, Mockito.times(1)).getConfigDir();
boolean foundFileWatcher = false;
for (Thread thread : Thread.getAllStackTraces().keySet()) {
foundFileWatcher |= (thread instanceof FileWatchdog);
}
Assert.assertTrue(foundFileWatcher);
Mockito.verify(runtimeInfo, Mockito.times(1)).setAttribute(Mockito.eq(RuntimeInfo.LOG4J_CONFIGURATION_URL_ATTR),
Mockito.any());
}
java类org.apache.log4j.helpers.FileWatchdog的实例源码
TestLogConfigurator.java 文件源码
项目:datacollector
阅读 19
收藏 0
点赞 0
评论 0
Log4jListener.java 文件源码
项目:VirtualEncoder
阅读 24
收藏 0
点赞 0
评论 0
/**
* 获取配置信息
*/
@Override
public void setConfiguration(Configuration cfg)
throws ConfigurationException {
String config = cfg.get("config");
long watch = cfg.getLong("watch");
this.logName = cfg.get("log-name");
if (watch == 0)
watch = FileWatchdog.DEFAULT_DELAY;
if ((config != null) && (!config.trim().equals(""))) {
DOMConfigurator.configureAndWatch(config, watch);
}
setLevel(cfg.get("priority"));
}
TestLogConfigurator.java 文件源码
项目:datacollector
阅读 43
收藏 0
点赞 0
评论 0
@After
public void cleanUp() throws Exception {
System.getProperties().remove("log4j.configuration");
System.getProperties().remove("log4j.defaultInitOverride");
for (Thread thread : Thread.getAllStackTraces().keySet()) {
if (thread instanceof FileWatchdog) {
Field interrupted = ((Class)thread.getClass().getGenericSuperclass()).getDeclaredField("interrupted");
interrupted.setAccessible(true);
interrupted.set(thread, true);
thread.interrupt();
}
}
}
TestLogConfigurator.java 文件源码
项目:datacollector
阅读 19
收藏 0
点赞 0
评论 0
@Test
public void testClasspathLog4jConfig() {
RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
File configDir = new File("target", UUID.randomUUID().toString());
Assert.assertTrue(configDir.mkdirs());
Mockito.when(runtimeInfo.getConfigDir()).thenReturn(configDir.getAbsolutePath());
Mockito.when(runtimeInfo.getLog4jPropertiesFileName()).thenReturn("log4j.properties");
new LogConfigurator(runtimeInfo).configure();
Mockito.verify(runtimeInfo, Mockito.times(1)).getConfigDir();
for (Thread thread : Thread.getAllStackTraces().keySet()) {
Assert.assertFalse(thread instanceof FileWatchdog);
}
Mockito.verify(runtimeInfo, Mockito.times(1)).setAttribute(Mockito.eq(RuntimeInfo.LOG4J_CONFIGURATION_URL_ATTR),
Mockito.any());
}
PropertyConfigurator.java 文件源码
项目:cacheonix-core
阅读 29
收藏 0
点赞 0
评论 0
/**
Like {@link #configureAndWatch(String, long)} except that the
default delay as defined by {@link FileWatchdog#DEFAULT_DELAY} is
used.
@param configFilename A file in key=value format.
*/
static
public
void configureAndWatch(String configFilename) {
configureAndWatch(configFilename, FileWatchdog.DEFAULT_DELAY);
}
DOMConfigurator.java 文件源码
项目:cacheonix-core
阅读 25
收藏 0
点赞 0
评论 0
/**
Like {@link #configureAndWatch(String, long)} except that the
default delay as defined by {@link FileWatchdog#DEFAULT_DELAY} is
used.
@param configFilename A log4j configuration file in XML format.
*/
static
public
void configureAndWatch(String configFilename) {
configureAndWatch(configFilename, FileWatchdog.DEFAULT_DELAY);
}
PropertyConfigurator.java 文件源码
项目:daq-eclipse
阅读 27
收藏 0
点赞 0
评论 0
/**
Like {@link #configureAndWatch(String, long)} except that the
default delay as defined by {@link FileWatchdog#DEFAULT_DELAY} is
used.
@param configFilename A file in key=value format.
*/
static
public
void configureAndWatch(String configFilename) {
configureAndWatch(configFilename, FileWatchdog.DEFAULT_DELAY);
}
DOMConfigurator.java 文件源码
项目:daq-eclipse
阅读 20
收藏 0
点赞 0
评论 0
/**
Like {@link #configureAndWatch(String, long)} except that the
default delay as defined by {@link FileWatchdog#DEFAULT_DELAY} is
used.
@param configFilename A log4j configuration file in XML format.
*/
static
public
void configureAndWatch(String configFilename) {
configureAndWatch(configFilename, FileWatchdog.DEFAULT_DELAY);
}
PropertyConfigurator.java 文件源码
项目:nabs
阅读 33
收藏 0
点赞 0
评论 0
/**
Like {@link #configureAndWatch(String, long)} except that the
default delay as defined by {@link FileWatchdog#DEFAULT_DELAY} is
used.
@param configFilename A file in key=value format.
*/
static
public
void configureAndWatch(String configFilename) {
configureAndWatch(configFilename, FileWatchdog.DEFAULT_DELAY);
}