public static void splitAndSetLogger(final String propKey, final Properties confProps) { String propVal = confProps.getProperty(propKey); if (propVal.contains(",")) { String[] tokens = propVal.split(","); for (String token : tokens) { if (Level.getLevel(token) == null) { System.setProperty("hive.root.logger", token); } else { System.setProperty("hive.log.level", token); } } } else { System.setProperty(propKey, confProps.getProperty(propKey)); } }
public static void splitAndSetLogger(final String propKey, final Properties confProps) { String propVal = confProps.getProperty(propKey); if (propVal.contains(",")) { String[] tokens = propVal.split(","); for (String token : tokens) { if (Level.getLevel(token) == null) { System.setProperty("hive.root.logger", token); } else { System.setProperty("hive.log.level", token); } } } else { System.setProperty(propKey, confProps.getProperty(propKey)); } }
public void setLoggerLevel(LoggerContext logContext, String loggerName, String newLevelStr) { Level newLevel = Level.getLevel(newLevelStr); Configuration configuration = logContext.getConfiguration(); LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName); if (loggerConfig.getName().equalsIgnoreCase(loggerName)) { LOG.info("Setting {} log level to: {}", loggerConfig, newLevel); loggerConfig.setLevel(newLevel); } else { // create a new config. Make it additive (true) s.t. inherit parents appenders LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, newLevel, true); LOG.info("Adding config for: {} with level: {}", newLoggerConfig, newLevel); configuration.addLogger(loggerName, newLoggerConfig); } } }
public BasicConfiguration() { super(null, ConfigurationSource.NULL_SOURCE); final LoggerConfig root = getRootLogger(); final String name = System.getProperty(DEFAULT_LEVEL); final Level level = (name != null && Level.getLevel(name) != null) ? Level.getLevel(name) : Level.ERROR; root.setLevel(level); } }
@Test public void testNameOnly() throws IOException { final Level expected = Level.getLevel("DEBUG"); final String str = writer.writeValueAsString(expected); Assert.assertTrue(str.contains("DEBUG")); final Level actual = reader.readValue(str); Assert.assertEquals(expected, actual); } }
for (ConfLogger logger : confLoggers.getLoggers()) { String loggerName = logger.getLogger(); Level logLevel = Level.getLevel(logger.getLevel()); if (logLevel == null) { LOG.warn("Invalid log level: {} for logger: {}. Ignoring reconfiguration.", loggerName, logger.getLevel());
@Test public void testCompletionContainsOnlyLog4jLevels() { LogLevelConverter converter = new LogLevelConverter(); List<Completion> completions = new ArrayList<>(); converter.getAllPossibleValues(completions, null, null, null, null); assertThat(completions.size()).isEqualTo(8); for (Completion completion : completions) { String level = completion.getValue(); assertThat(Level.getLevel(level)).isNotNull(); } } }
@Test public void testForNameEquals() { final String name = "Foo"; final int intValue = 1; final Level level = Level.forName(name, intValue); assertNotNull(level); assertEquals(level, Level.forName(name, intValue)); assertEquals(level, Level.getLevel(name)); assertEquals(intValue, Level.getLevel(name).intLevel()); }
@Override public Level parse(String s) { if (s == null) { throw new IllegalArgumentException("Logging level cannot be null"); } final Level level = Level.getLevel(s); if (level == null) { throw new IllegalArgumentException("Unrecognized logging level: " + s); } return level; }
private static Level getLevel(final String name) { return Level.getLevel(name.toUpperCase(Locale.ROOT)); }
public static void splitAndSetLogger(final String propKey, final Properties confProps) { String propVal = confProps.getProperty(propKey); if (propVal.contains(",")) { String[] tokens = propVal.split(","); for (String token : tokens) { if (Level.getLevel(token) == null) { System.setProperty("hive.root.logger", token); } else { System.setProperty("hive.log.level", token); } } } else { System.setProperty(propKey, confProps.getProperty(propKey)); } }
@Override public void setLevel(final String level) { loggerConfig.setLevel(Level.getLevel(level)); loggerContext.updateLoggers(); }
if (targetAttribute.getKey().equalsIgnoreCase(attribute.getKey())) { if (attribute.getKey().equalsIgnoreCase(STATUS)) { final Level targetLevel = Level.getLevel(targetAttribute.getValue().toUpperCase()); final Level sourceLevel = Level.getLevel(attribute.getValue().toUpperCase()); if (targetLevel != null && sourceLevel != null) { if (sourceLevel.isLessSpecificThan(targetLevel)) {
/** * Looks up the logger in the logger factory, * and attempts to find the real logger instance * based on the underlying logging framework * and retrieve the logger object. Then, updates the level. * This functionality at this point is heavily dependant * on the log4j API. * * @param loggerName the logger name * @param loggerLevel the logger level * @param additive the additive nature of the logger */ @WriteOperation public void updateLoggerLevel(@Selector final String loggerName, final String loggerLevel, final boolean additive) { val loggerConfigs = getLoggerConfigurations(); loggerConfigs.stream() .filter(cfg -> cfg.getName().equals(loggerName)) .forEachOrdered(cfg -> { cfg.setLevel(Level.getLevel(loggerLevel)); cfg.setAdditive(additive); }); this.loggerContext.updateLoggers(); }
for (ConfLogger logger : confLoggers.getLoggers()) { String loggerName = logger.getLogger(); Level logLevel = Level.getLevel(logger.getLevel()); if (logLevel == null) { LOG.warn("Invalid log level: {} for logger: {}. Ignoring reconfiguration.", loggerName, logger.getLevel());
@Test public void levels() { for (StandardLevel std : StandardLevel.values()) { Level level = Level.getLevel(std.name()); Assertions.assertEquals(std, LevelTag.get(level).standardLevel()); } }