Search in sources :

Example 6 with DefaultConfiguration

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

the class JdbcAppenderBenchmark method setup.

@Setup
public void setup() throws Exception {
    connectionHSQLDB = getConnectionHSQLDB();
    connectionH2 = getConnectionH2();
    createTable(connectionHSQLDB, toCreateTableSqlStringHQLDB("fmLogEntry"));
    createTable(connectionH2, toCreateTableSqlStringH2("fmLogEntry"));
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2-jdbc-appender.xml");
    final LoggerContext context = LoggerContext.getContext(false);
    if (context.getConfiguration() instanceof DefaultConfiguration) {
        context.reconfigure();
    }
    StatusLogger.getLogger().reset();
    loggerH2 = LogManager.getLogger("H2Logger");
    loggerHSQLDB = LogManager.getLogger("HSQLDBLogger");
}
Also used : DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Setup(org.openjdk.jmh.annotations.Setup)

Example 7 with DefaultConfiguration

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

the class JpaAppenderBenchmark method setup.

@Setup
public void setup() throws Exception {
    connectionHSQLDB = getConnectionHSQLDB();
    connectionH2 = getConnectionH2();
    System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "log4j2-jpa-appender.xml");
    final LoggerContext context = LoggerContext.getContext(false);
    if (context.getConfiguration() instanceof DefaultConfiguration) {
        context.reconfigure();
    }
    StatusLogger.getLogger().reset();
    loggerH2 = LogManager.getLogger("H2Logger");
    loggerHSQLDB = LogManager.getLogger("HSQLDBLogger");
}
Also used : DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Setup(org.openjdk.jmh.annotations.Setup)

Example 8 with DefaultConfiguration

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

the class AsyncLoggerConfigTest method testIncludeLocationDefaultsToFalse.

@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());
}
Also used : DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) Test(org.junit.Test)

Example 9 with DefaultConfiguration

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

the class ScriptConditionTest method testSelectFilesToDelete3.

@Test
@Category(Scripts.Groovy.class)
public void testSelectFilesToDelete3() {
    final Configuration config = new DefaultConfiguration();
    // creates the ScriptManager
    config.initialize();
    final List<PathWithAttributes> pathList = new ArrayList<>();
    pathList.add(new PathWithAttributes(Paths.get("/path/1/abc/a.txt"), new DummyFileAttributes()));
    pathList.add(new PathWithAttributes(Paths.get("/path/2/abc/bbb.txt"), new DummyFileAttributes()));
    pathList.add(new PathWithAttributes(Paths.get("/path/3/abc/c.txt"), new DummyFileAttributes()));
    final String scriptText = //
    "" + //
    "import java.nio.file.*;" + //
    "def pattern = ~/(\\d*)[\\/\\\\]abc[\\/\\\\].*\\.txt/;" + //
    "assert pattern.getClass() == java.util.regex.Pattern;" + "def copy = pathList.collect{it};" + //
    "pathList.each { pathWithAttribs -> \n" + //
    "  def relative = basePath.relativize pathWithAttribs.path;" + //
    "  println 'relative path: ' + relative;" + "  def str = relative.toString();" + //
    "  def m = pattern.matcher(str);" + //
    "  if (m.find()) {" + //
    "    def index = m.group(1) as int;" + //
    "    println 'extracted index: ' + index;" + "    def isOdd = (index % 2) == 1;" + //
    "    println 'is odd: ' + isOdd;" + "    if (isOdd) { copy.remove pathWithAttribs}" + //
    "  }" + //
    "}" + "println copy;" + "copy;";
    final Script script = new Script("test", "groovy", scriptText);
    final ScriptCondition condition = new ScriptCondition(script, config);
    final Path base = Paths.get("/path");
    final List<PathWithAttributes> result = condition.selectFilesToDelete(base, pathList);
    assertEquals(1, result.size());
    assertEquals(Paths.get("/path/2/abc/bbb.txt"), result.get(0).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) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 10 with DefaultConfiguration

use of org.apache.logging.log4j.core.config.DefaultConfiguration 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)

Aggregations

DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)14 Configuration (org.apache.logging.log4j.core.config.Configuration)10 Test (org.junit.Test)7 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)3 LoggerContext (org.apache.logging.log4j.core.LoggerContext)3 Script (org.apache.logging.log4j.core.script.Script)3 Setup (org.openjdk.jmh.annotations.Setup)3 File (java.io.File)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Timer (org.apache.logging.log4j.Timer)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1 PluginConfiguration (org.apache.logging.log4j.core.config.plugins.PluginConfiguration)1 PluginFactory (org.apache.logging.log4j.core.config.plugins.PluginFactory)1 XmlConfiguration (org.apache.logging.log4j.core.config.xml.XmlConfiguration)1 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)1 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)1 SmtpManager (org.apache.logging.log4j.core.net.SmtpManager)1