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());
}
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());
}
}
Aggregations