Search in sources :

Example 71 with Configuration

use of org.apache.logging.log4j.core.config.Configuration in project ignite by apache.

the class Log4J2Logger method setLevel.

/**
     * Sets level for internal log4j implementation.
     *
     * @param level Log level to set.
     */
public void setLevel(Level level) {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration conf = ctx.getConfiguration();
    conf.getLoggerConfig(impl.getName()).setLevel(level);
    ctx.updateLoggers(conf);
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 72 with Configuration

use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.

the class ScriptConditionTest method testSelectFilesToDelete2.

@Test
public void testSelectFilesToDelete2() {
    final Configuration config = new DefaultConfiguration();
    // creates the ScriptManager
    config.initialize();
    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());
}
Also used : Path(java.nio.file.Path) Script(org.apache.logging.log4j.core.script.Script) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) ArrayList(java.util.ArrayList) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) Test(org.junit.Test)

Example 73 with Configuration

use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.

the class RollingFileAppenderAccessTest method testAccessManagerWithBuilder.

/**
     * Not a real test, just make sure we can compile access to the typed manager.
     *
     * @throws IOException
     */
@Test
public void testAccessManagerWithBuilder() throws IOException {
    try (final LoggerContext ctx = LoggerContext.getContext(false)) {
        final Configuration config = ctx.getConfiguration();
        final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp");
        file.deleteOnExit();
        // @formatter:off
        final RollingFileAppender appender = RollingFileAppender.newBuilder().withFileName(file.getCanonicalPath()).withFilePattern("FilePattern").withName("Name").withPolicy(OnStartupTriggeringPolicy.createPolicy(1)).setConfiguration(config).build();
        // @formatter:on
        final RollingFileManager manager = appender.getManager();
        // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use generics to type their
        // access.
        Assert.assertNotNull(manager.getRolloverStrategy());
        Assert.assertNotNull(manager.getTriggeringPolicy());
    }
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) LoggerContext(org.apache.logging.log4j.core.LoggerContext) File(java.io.File) Test(org.junit.Test)

Example 74 with Configuration

use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.

the class ScriptConditionTest method testSelectFilesToDelete.

@Test
public void testSelectFilesToDelete() {
    final Configuration config = new DefaultConfiguration();
    // creates the ScriptManager
    config.initialize();
    // script that returns pathList
    final Script script = new Script("test", "javascript", "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);
}
Also used : Path(java.nio.file.Path) Script(org.apache.logging.log4j.core.script.Script) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) Configuration(org.apache.logging.log4j.core.config.Configuration) ArrayList(java.util.ArrayList) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) Test(org.junit.Test)

Example 75 with Configuration

use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.

the class DeleteActionTest method create.

private static DeleteAction create(final String path, final boolean followLinks, final int maxDepth, final boolean testMode, final PathCondition[] conditions) {
    final Configuration config = new BasicConfigurationFactory().new BasicConfiguration();
    final DeleteAction delete = DeleteAction.createDeleteAction(path, followLinks, maxDepth, testMode, null, conditions, null, config);
    return delete;
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) DeleteAction(org.apache.logging.log4j.core.appender.rolling.action.DeleteAction) BasicConfigurationFactory(org.apache.logging.log4j.core.BasicConfigurationFactory)

Aggregations

Configuration (org.apache.logging.log4j.core.config.Configuration)105 LoggerContext (org.apache.logging.log4j.core.LoggerContext)54 Test (org.junit.Test)43 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)39 Appender (org.apache.logging.log4j.core.Appender)21 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)15 File (java.io.File)12 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)9 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)9 Path (java.nio.file.Path)7 Level (org.apache.logging.log4j.Level)7 NullConfiguration (org.apache.logging.log4j.core.config.NullConfiguration)7 ArrayList (java.util.ArrayList)6 Logger (org.apache.logging.log4j.Logger)6 Filter (org.apache.logging.log4j.core.Filter)6 AbstractLogger (org.apache.logging.log4j.spi.AbstractLogger)6 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)5 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)5 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)4 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)4