Search in sources :

Example 1 with LevelRangeFilter

use of org.apache.logging.log4j.core.filter.LevelRangeFilter in project mondrian by pentaho.

the class SchemaTest method testUnknownUsages1.

public void testUnknownUsages1() {
    if (!MondrianProperties.instance().ReadAggregates.get()) {
        return;
    }
    final Logger logger = LogManager.getLogger(AggTableManager.class);
    propSaver.setAtLeast(logger, org.apache.logging.log4j.Level.WARN);
    final StringWriter sw = new StringWriter();
    final LevelRangeFilter filter = LevelRangeFilter.createFilter(org.apache.logging.log4j.Level.WARN, null, null, null);
    final Appender appender = WriterAppender.newBuilder().setFilter(filter).setLayout(PatternLayout.createDefaultLayout()).setTarget(sw).build();
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
    loggerConfig.addAppender(appender, org.apache.logging.log4j.Level.ALL, null);
    ctx.updateLoggers();
    try {
        final TestContext testContext = TestContext.instance().withSchema("<?xml version=\"1.0\"?>\n" + "<Schema name=\"FoodMart\">\n" + "<Cube name=\"Denormalized Sales\">\n" + "  <Table name=\"sales_fact_1997\">\n" + "    <AggExclude pattern=\"agg_c_14_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_l_05_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_g_ms_pcat_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_ll_01_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_c_special_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_l_04_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_pl_01_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_c_10_sales_fact_1997\"/>\n" + "    <AggExclude pattern=\"agg_lc_06_sales_fact_1997\"/>\n" + "    <AggName name=\"agg_l_03_sales_fact_1997\">\n" + "      <AggFactCount column=\"fact_count\"/>\n" + "      <AggMeasure name=\"[Measures].[Store Cost]\" column=\"store_cost\" />\n" + "      <AggMeasure name=\"[Measures].[Store Sales]\" column=\"store_sales\" />\n" + "      <AggMeasure name=\"[Measures].[Unit Sales]\" column=\"unit_sales\" />\n" + "      <AggLevel name=\"[Customer].[Customer ID]\" column=\"customer_id\" />\n" + "      <AggForeignKey factColumn=\"time_id\" aggColumn=\"time_id\" />\n" + "     </AggName>\n" + "  </Table>\n" + "  <Dimension name=\"Time\" type=\"TimeDimension\" foreignKey=\"time_id\">\n" + "    <Hierarchy hasAll=\"false\" primaryKey=\"time_id\">\n" + "      <Table name=\"time_by_day\"/>\n" + "      <Level name=\"Year\" column=\"the_year\" type=\"Numeric\" uniqueMembers=\"true\"\n" + "          levelType=\"TimeYears\"/>\n" + "      <Level name=\"Quarter\" column=\"quarter\" uniqueMembers=\"false\"\n" + "          levelType=\"TimeQuarters\"/>\n" + "      <Level name=\"Month\" column=\"month_of_year\" uniqueMembers=\"false\" type=\"Numeric\"\n" + "          levelType=\"TimeMonths\"/>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "  <Dimension name=\"Customer\">\n" + "    <Hierarchy hasAll=\"true\" primaryKey=\"customer_id\">\n" + "      <Level name=\"Customer ID\" column=\"customer_id\"/>\n" + "    </Hierarchy>" + "  </Dimension>" + "  <Dimension name=\"Product\">\n" + "    <Hierarchy hasAll=\"true\" primaryKey=\"product_id\">\n" + "      <Level name=\"Product ID\" column=\"product_id\"/>\n" + "    </Hierarchy>" + "  </Dimension>" + "  <Measure name=\"Store Cost\" column=\"store_cost\" aggregator=\"sum\"\n" + "      formatString=\"#,###.00\"/>\n" + "  <Measure name=\"Store Sales\" column=\"store_sales\" aggregator=\"sum\"\n" + "      formatString=\"#,###.00\"/>\n" + "  <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n" + "      formatString=\"#,###\"/>\n" + "</Cube>\n" + "</Schema>");
        testContext.assertQueryReturns("select from [Denormalized Sales]", "Axis #0:\n" + "{}\n" + "225,627.23");
    } finally {
        loggerConfig.removeAppender(appender.getName());
        ctx.updateLoggers();
    }
    TestContext.assertEqualsVerbose("WARN - Recognizer.checkUnusedColumns: Candidate aggregate table 'agg_l_03_sales_fact_1997' for fact table 'sales_fact_1997' has a column 'time_id' with unknown usage.\n", sw.toString());
}
Also used : WriterAppender(org.apache.logging.log4j.core.appender.WriterAppender) Appender(org.apache.logging.log4j.core.Appender) Configuration(org.apache.logging.log4j.core.config.Configuration) LevelRangeFilter(org.apache.logging.log4j.core.filter.LevelRangeFilter) Logger(org.apache.logging.log4j.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 2 with LevelRangeFilter

use of org.apache.logging.log4j.core.filter.LevelRangeFilter in project logging-log4j2 by apache.

the class PropertiesConfigurationTest method testConsoleAppenderLevelRangeFilter.

@Test
public void testConsoleAppenderLevelRangeFilter() throws Exception {
    try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3326.properties")) {
        final Configuration configuration = loggerContext.getConfiguration();
        assertNotNull(configuration);
        final Appender appender = configuration.getAppender("CUSTOM");
        assertNotNull(appender);
        final Filterable filterable = (Filterable) appender;
        final CompositeFilter filter = (CompositeFilter) filterable.getFilter();
        final org.apache.logging.log4j.core.Filter[] filters = filter.getFiltersArray();
        final LevelRangeFilter customFilterReal = (LevelRangeFilter) ((FilterWrapper) ((FilterAdapter) filters[0]).getFilter()).getFilter();
        assertEquals(Level.ALL, customFilterReal.getMinLevel());
        final LevelRangeFilter defaultFilter = (LevelRangeFilter) ((FilterWrapper) ((FilterAdapter) filters[1]).getFilter()).getFilter();
        assertEquals(Level.TRACE, defaultFilter.getMinLevel());
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) ListAppender(org.apache.log4j.ListAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) CompositeFilter(org.apache.logging.log4j.core.filter.CompositeFilter) Configuration(org.apache.logging.log4j.core.config.Configuration) CompositeFilter(org.apache.logging.log4j.core.filter.CompositeFilter) LevelRangeFilter(org.apache.logging.log4j.core.filter.LevelRangeFilter) Filterable(org.apache.logging.log4j.core.filter.Filterable) LevelRangeFilter(org.apache.logging.log4j.core.filter.LevelRangeFilter) FilterAdapter(org.apache.log4j.bridge.FilterAdapter) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Test(org.junit.Test)

Aggregations

Appender (org.apache.logging.log4j.core.Appender)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 LevelRangeFilter (org.apache.logging.log4j.core.filter.LevelRangeFilter)2 ListAppender (org.apache.log4j.ListAppender)1 FilterAdapter (org.apache.log4j.bridge.FilterAdapter)1 Logger (org.apache.logging.log4j.Logger)1 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)1 WriterAppender (org.apache.logging.log4j.core.appender.WriterAppender)1 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)1 CompositeFilter (org.apache.logging.log4j.core.filter.CompositeFilter)1 Filterable (org.apache.logging.log4j.core.filter.Filterable)1 Test (org.junit.Test)1