org.apache.log4j.helpers.FileWatchdog Java Examples
The following examples show how to use
org.apache.log4j.helpers.FileWatchdog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestLogConfigurator.java From datacollector with Apache License 2.0 | 6 votes |
@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()); }
Example #2
Source File: GridLog4jConfigUpdateTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Check that changing log4j config file causes the logger configuration to be updated. * String-accepting constructor is used. */ @Test public void testConfigChangeStringConstructorDefaultDelay() throws Exception { checkConfigUpdate(new Log4JLoggerSupplier() { @Override public Log4JLogger get(File cfgFile) throws Exception { return new Log4JLogger(cfgFile.getPath()); } }, FileWatchdog.DEFAULT_DELAY + 5000); // use larger delay to avoid relying on exact timing }
Example #3
Source File: TestLogConfigurator.java From datacollector with Apache License 2.0 | 5 votes |
@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(); } } }
Example #4
Source File: TestLogConfigurator.java From datacollector with Apache License 2.0 | 5 votes |
@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()); }
Example #5
Source File: Log4JLogger.java From ignite with Apache License 2.0 | 2 votes |
/** * Creates new logger with given configuration {@code path}. * Calling this constructor is equivalent to calling {@code Log4JLogger(path, FileWatchdog.DEFAULT_DELAY}. * * @param path Path to log4j configuration XML file. * @throws IgniteCheckedException Thrown in case logger can't be created. */ public Log4JLogger(final String path) throws IgniteCheckedException { this(path, FileWatchdog.DEFAULT_DELAY); }
Example #6
Source File: Log4JLogger.java From ignite with Apache License 2.0 | 2 votes |
/** * Creates new logger with given configuration {@code cfgFile}. * Calling this constructor is equivalent to calling {@code Log4JLogger(cfgFile, FileWatchdog.DEFAULT_DELAY}. * * @param cfgFile Log4j configuration XML file. * @throws IgniteCheckedException Thrown in case logger can't be created. */ public Log4JLogger(File cfgFile) throws IgniteCheckedException { this(cfgFile, FileWatchdog.DEFAULT_DELAY); }
Example #7
Source File: Log4JLogger.java From ignite with Apache License 2.0 | 2 votes |
/** * Creates new logger with given configuration {@code cfgUrl}. * Calling this constructor is equivalent to calling {@code Log4JLogger(cfgUrl, FileWatchdog.DEFAULT_DELAY}. * * @param cfgUrl URL for Log4j configuration XML file. * @throws IgniteCheckedException Thrown in case logger can't be created. */ public Log4JLogger(final URL cfgUrl) throws IgniteCheckedException { this(cfgUrl, FileWatchdog.DEFAULT_DELAY); }
Example #8
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | votes |
/** 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); }
Example #9
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | votes |
/** 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); }