@Test(expected = NullPointerException.class) public void testConstructorDisallowsNullScript() { new ScriptCondition(null, new DefaultConfiguration()); }
@Before public void before() { contextConfigurer = new LoggerContextConfigurer(); when(context.isStandlone()).thenReturn(true); when(context.getConfiguration()).thenReturn(configuration); converter = null; doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { converter = invocation.getArguments()[1]; return null; } }).when(configuration).addComponent(eq("Converter"), anyObject()); when(configuration.getComponent(CONVERTER_COMPONENT)).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return converter; } }); }
@Test public void configurationMonitor() throws Exception { WatchManager watchManager = mock(WatchManager.class); when(configuration.getWatchManager()).thenReturn(watchManager); when(context.getConfigFile()).thenReturn(new File(CURRENT_DIRECTORY).toURI()); contextConfigurer.configure(context); ArgumentCaptor<ConfiguratonFileWatcher> captor = ArgumentCaptor.forClass(ConfiguratonFileWatcher.class); verify(watchManager).watchFile(any(File.class), captor.capture()); assertThat(captor.getValue(), instanceOf(ConfiguratonFileWatcher.class)); verify(watchManager).setIntervalSeconds(eq((int) TimeUnit.MILLISECONDS.toSeconds(MONITOR_INTERVAL))); }
/** * Constructor to create the default configuration. */ public DefaultConfiguration() { super(null, ConfigurationSource.NULL_SOURCE); setToDefault(); }
@Test public void testCreateConditionReturnsNullForNullScript() { assertNull(ScriptCondition.createCondition(null, new DefaultConfiguration())); }
@Test public void testSelectFilesToDelete() { final Configuration config = new DefaultConfiguration(); config.initialize(); // creates the ScriptManager final Script script = new Script("test", "javascript", "pathList;"); // script that returns pathList final ScriptCondition condition = new ScriptCondition(script, config); final List<PathWithAttributes> pathList = new ArrayList<>(); final Path base = Paths.get("baseDirectory"); final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); assertSame(result, pathList); }
@Test public void testPolicy() throws Exception { final Configuration configuration = new DefaultConfiguration(); final Path target = Paths.get(TARGET_FILE); target.toFile().getParentFile().mkdirs();
@Test public void testIncludeLocationDefaultsToFalse() { final LoggerConfig rootLoggerConfig = AsyncLoggerConfig.RootLogger.createLogger( null, "INFO", null, new AppenderRef[0], null, new DefaultConfiguration(), null); assertFalse("Include location should default to false for async logggers", rootLoggerConfig.isIncludeLocation()); final LoggerConfig loggerConfig = AsyncLoggerConfig.createLogger( null, "INFO", "com.foo.Bar", null, new AppenderRef[0], null, new DefaultConfiguration(), null); assertFalse("Include location should default to false for async logggers", loggerConfig.isIncludeLocation()); } }
@Test public void testSelectFilesToDelete2() { final Configuration config = new DefaultConfiguration(); config.initialize(); // creates the ScriptManager final List<PathWithAttributes> pathList = new ArrayList<>(); pathList.add(new PathWithAttributes(Paths.get("/path/1"), new DummyFileAttributes())); pathList.add(new PathWithAttributes(Paths.get("/path/2"), new DummyFileAttributes())); pathList.add(new PathWithAttributes(Paths.get("/path/3"), new DummyFileAttributes())); final String scriptText = "pathList.remove(1);" // + "pathList;"; final Script script = new Script("test", "javascript", scriptText); final ScriptCondition condition = new ScriptCondition(script, config); final Path base = Paths.get("baseDirectory"); final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList); assertSame(result, pathList); assertEquals(2, result.size()); assertEquals(Paths.get("/path/1"), result.get(0).getPath()); assertEquals(Paths.get("/path/3"), result.get(1).getPath()); }
@Test @Category(Scripts.Groovy.class) public void testSelectFilesToDelete3() { final Configuration config = new DefaultConfiguration();
@Test public void testDefaultLayout() throws Exception { // @formatter:off Assert.assertNotNull(RollingFileAppender.newBuilder() .withName(RollingFileAppenderLayoutTest.class.getName()) .setConfiguration(new DefaultConfiguration()) .withFileName("log.txt") .withFilePattern("FilePattern") .withPolicy(OnStartupTriggeringPolicy.createPolicy(1)) .withCreateOnDemand(true) // no need to clutter up test folder with another file .build().getLayout()); // @formatter:on } }
@Test public void testPatternWithConfiguration() throws Exception { final Configuration config = new DefaultConfiguration(); final MessagePatternConverter converter = MessagePatternConverter.newInstance(config, null); Message msg = new SimpleMessage("Hello!"); LogEvent event = Log4jLogEvent.newBuilder() // .setLoggerName("MyLogger") // .setLevel(Level.DEBUG) // .setMessage(msg).build(); StringBuilder sb = new StringBuilder(); converter.format(event, sb); assertEquals("Unexpected result", "Hello!", sb.toString()); event = Log4jLogEvent.newBuilder() // .setLoggerName("MyLogger") // .setLevel(Level.DEBUG) // .setMessage(null).build(); sb = new StringBuilder(); converter.format(event, sb); assertEquals("Incorrect length: " + sb, 0, sb.length()); msg = new SimpleMessage(null); event = Log4jLogEvent.newBuilder() // .setLoggerName("MyLogger") // .setLevel(Level.DEBUG) // .setMessage(msg).build(); sb = new StringBuilder(); converter.format(event, sb); assertEquals("Incorrect length: " + sb, 4, sb.length()); }
/** * Creates a YAML Layout using the default settings. Useful for testing. * * @return A YAML Layout. */ public static AbstractJacksonLayout createDefaultLayout() { return new YamlLayout(new DefaultConfiguration(), false, false, false, false, false, DEFAULT_HEADER, DEFAULT_FOOTER, StandardCharsets.UTF_8, true, false, false); } }
/** * Creates a JSON Layout using the default settings. Useful for testing. * * @return A JSON Layout. */ public static JsonLayout createDefaultLayout() { return new JsonLayout(new DefaultConfiguration(), false, false, false, false, false, false, DEFAULT_HEADER, DEFAULT_FOOTER, StandardCharsets.UTF_8, true, false, false); }
@Override public PatternLayout build() { // fall back to DefaultConfiguration if (configuration == null) { configuration = new DefaultConfiguration(); } return new PatternLayout(configuration, regexReplacement, pattern, patternSelector, charset, alwaysWriteExceptions, disableAnsi, noConsoleNoAnsi, header, footer); } }
private void configureDefaults() { if (m_log4jContext == null) { m_log4jContext = new LoggerContext(LOGGER_CONTEXT_NAME); } m_log4jContext.start(new DefaultConfiguration()); String levelName; levelName = m_bundleContext.getProperty( DEFAULT_SERVICE_LOG_LEVEL ); if( levelName == null ) { levelName = "DEBUG"; } else { levelName = levelName.trim(); } m_logLevel = convertLevel( levelName ); }
/** * Initialize logs. This is called before {@link ConfigurationGenerator#init()} so the {@code logDir} field is not * yet initialized * * @since 5.4.2 */ public void initLogs() { File logFile = getLogConfFile(); String logDirectory = System.getProperty(org.nuxeo.common.Environment.NUXEO_LOG_DIR); if (logDirectory == null) { System.setProperty(org.nuxeo.common.Environment.NUXEO_LOG_DIR, getLogDir().getPath()); } if (logFile == null || !logFile.exists()) { System.out.println("No logs configuration, will setup a basic one."); Configurator.initialize(new DefaultConfiguration()); } else { System.out.println("Try to configure logs with " + logFile); Configurator.initialize(Log4JHelper.newConfiguration(logFile)); } log.info("Logs successfully configured."); }
public static void configureFileLogger(String filePath, String fileName) { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration logConfiguration = ctx.getConfiguration(); RollingFileAppender appender = createRollingFileAppender(String.format(filePath, fileName), "'.'%d{yyyy-MM-dd}", "defaultFileAppender", new DefaultConfiguration()); doAddAppender(logConfiguration, appender); ctx.updateLoggers(); }
@Override public synchronized ILogger init(ILog owner, String loggerName) throws Exception { if (!__inited) { __owner = owner; __loggerName = loggerName; // if (!__logInited) { ConfigurationSource _source = new ConfigurationSource(new FileInputStream(__owner.getModuleCfg().getConfigFile())); Configurator.initialize(null, _source); final Configuration _config = new DefaultConfiguration(); ConfigurationFactory.setConfigurationFactory(new XmlConfigurationFactory() { @Override public Configuration getConfiguration(ConfigurationSource source) { return _config; } }); ConfigurationFactory.getInstance().getConfiguration(_source); __logInited = true; } __logger = LogManager.getLogger(StringUtils.defaultIfBlank(loggerName, __owner.getModuleCfg().getLoggerName())); __inited = true; } return this; }
"Set system property 'log4j2.debug' " + "to show Log4j2 internal initialization logging."); return new DefaultConfiguration();