Java Code Examples for org.elasticsearch.common.logging.Loggers#setLevel()
The following examples show how to use
org.elasticsearch.common.logging.Loggers#setLevel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScopedSettingsTests.java From crate with Apache License 2.0 | 5 votes |
@Test public void testLoggingUpdates() { final Level level = LogManager.getRootLogger().getLevel(); final Level testLevel = LogManager.getLogger("test").getLevel(); Level property = randomFrom(Level.values()); Settings.Builder builder = Settings.builder().put("logger.level", property); try { ClusterSettings settings = new ClusterSettings(builder.build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); IllegalArgumentException ex = expectThrows( IllegalArgumentException.class, () -> settings.validate(Settings.builder().put("logger._root", "boom").build(), false)); assertEquals("Unknown level constant [BOOM].", ex.getMessage()); assertEquals(level, LogManager.getRootLogger().getLevel()); settings.applySettings(Settings.builder().put("logger._root", "TRACE").build()); assertEquals(Level.TRACE, LogManager.getRootLogger().getLevel()); settings.applySettings(Settings.builder().build()); assertEquals(property, LogManager.getRootLogger().getLevel()); settings.applySettings(Settings.builder().put("logger.test", "TRACE").build()); assertEquals(Level.TRACE, LogManager.getLogger("test").getLevel()); settings.applySettings(Settings.builder().build()); assertEquals(property, LogManager.getLogger("test").getLevel()); } finally { Loggers.setLevel(LogManager.getRootLogger(), level); Loggers.setLevel(LogManager.getLogger("test"), testLevel); } }
Example 2
Source File: ScopedSettingsTests.java From crate with Apache License 2.0 | 5 votes |
@Test public void testFallbackToLoggerLevel() { final Level level = LogManager.getRootLogger().getLevel(); try { ClusterSettings settings = new ClusterSettings(Settings.builder().put("logger.level", "ERROR").build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); assertEquals(level, LogManager.getRootLogger().getLevel()); settings.applySettings(Settings.builder().put("logger._root", "TRACE").build()); assertEquals(Level.TRACE, LogManager.getRootLogger().getLevel()); settings.applySettings(Settings.builder().build()); // here we fall back to 'logger.level' which is our default. assertEquals(Level.ERROR, LogManager.getRootLogger().getLevel()); } finally { Loggers.setLevel(LogManager.getRootLogger(), level); } }
Example 3
Source File: LoggingListener.java From crate with Apache License 2.0 | 5 votes |
/** * Reset the logging levels to the state provided by the map. * * @param map the logging levels to apply * @return an empty map */ private Map<String, String> reset(final Map<String, String> map) { for (final Map.Entry<String, String> previousLogger : map.entrySet()) { final Logger logger = resolveLogger(previousLogger.getKey()); Loggers.setLevel(logger, previousLogger.getValue()); } return Collections.emptyMap(); }
Example 4
Source File: SystemPropsTestLoggingListener.java From crate with Apache License 2.0 | 5 votes |
private Map<String, String> processTestLogging() { Map<String, String> map = getLoggersAndLevelsFromSystemProperty(); if (map == null) { return null; } Map<String, String> previousValues = new HashMap<>(); for (Map.Entry<String, String> entry : map.entrySet()) { Logger logger = resolveLogger(entry.getKey()); previousValues.put(entry.getKey(), logger.getLevel().toString()); Loggers.setLevel(logger, entry.getValue()); } return previousValues; }
Example 5
Source File: SystemPropsTestLoggingListener.java From crate with Apache License 2.0 | 5 votes |
private Map<String, String> reset(Map<String, String> map) { if (map != null) { for (Map.Entry<String, String> previousLogger : map.entrySet()) { Logger logger = resolveLogger(previousLogger.getKey()); Loggers.setLevel(logger, previousLogger.getValue()); } } return null; }