use of org.apache.storm.generated.LogLevelAction in project storm by apache.
the class LogConfigManager method processLogConfigChange.
public void processLogConfigChange(LogConfig logConfig) {
if (null != logConfig) {
LOG.debug("Processing received log config: {}", logConfig);
TreeMap<String, LogLevel> loggers = new TreeMap<>(logConfig.get_named_logger_level());
LoggerContext logContext = (LoggerContext) LogManager.getContext(false);
Map<String, LogLevel> newLogConfigs = new HashMap<>();
for (Map.Entry<String, LogLevel> entry : loggers.entrySet()) {
String msgLoggerName = entry.getKey();
msgLoggerName = ("ROOT".equalsIgnoreCase(msgLoggerName)) ? LogManager.ROOT_LOGGER_NAME : msgLoggerName;
LogLevel loggerLevel = entry.getValue();
// the new-timeouts map now contains logger => timeout
if (loggerLevel.is_set_reset_log_level_timeout_epoch()) {
LogLevel copy = new LogLevel(loggerLevel);
if (originalLogLevels.containsKey(msgLoggerName)) {
copy.set_reset_log_level(originalLogLevels.get(msgLoggerName).name());
} else {
copy.set_reset_log_level(Level.INFO.name());
}
newLogConfigs.put(msgLoggerName, copy);
}
}
// Look for deleted log timeouts
TreeMap<String, LogLevel> latestConf = latestLogConfig.get();
if (latestConf != null) {
for (String loggerName : latestConf.descendingKeySet()) {
if (!newLogConfigs.containsKey(loggerName)) {
// if we had a timeout, but the timeout is no longer active
setLoggerLevel(logContext, loggerName, latestConf.get(loggerName).get_reset_log_level());
}
}
}
// the merged configs are only for the reset logic
for (String loggerName : new TreeSet<>(logConfig.get_named_logger_level().keySet())) {
LogLevel logLevel = logConfig.get_named_logger_level().get(loggerName);
loggerName = ("ROOT".equalsIgnoreCase(loggerName)) ? LogManager.ROOT_LOGGER_NAME : loggerName;
LogLevelAction action = logLevel.get_action();
if (action == LogLevelAction.UPDATE) {
setLoggerLevel(logContext, loggerName, logLevel.get_target_log_level());
}
}
logContext.updateLoggers();
latestLogConfig.set(new TreeMap<>(newLogConfigs));
LOG.debug("New merged log config is {}", latestLogConfig.get());
}
}
use of org.apache.storm.generated.LogLevelAction in project storm by apache.
the class Nimbus method setLogConfig.
@Override
public void setLogConfig(String topoId, LogConfig config) throws TException {
try {
setLogConfigCalls.mark();
Map<String, Object> topoConf = tryReadTopoConf(topoId, topoCache);
topoConf = Utils.merge(conf, topoConf);
String topoName = (String) topoConf.get(Config.TOPOLOGY_NAME);
checkAuthorization(topoName, topoConf, "setLogConfig");
IStormClusterState state = stormClusterState;
LogConfig mergedLogConfig = state.topologyLogConfig(topoId, null);
if (mergedLogConfig == null) {
mergedLogConfig = new LogConfig();
}
if (mergedLogConfig.is_set_named_logger_level()) {
Map<String, LogLevel> namedLoggers = mergedLogConfig.get_named_logger_level();
for (LogLevel level : namedLoggers.values()) {
level.set_action(LogLevelAction.UNCHANGED);
}
}
if (config.is_set_named_logger_level()) {
for (Entry<String, LogLevel> entry : config.get_named_logger_level().entrySet()) {
LogLevel logConfig = entry.getValue();
String loggerName = entry.getKey();
LogLevelAction action = logConfig.get_action();
if (loggerName.isEmpty()) {
throw new RuntimeException("Named loggers need a valid name. Use ROOT for the root logger");
}
switch(action) {
case UPDATE:
setLoggerTimeouts(logConfig);
mergedLogConfig.put_to_named_logger_level(loggerName, logConfig);
break;
case REMOVE:
Map<String, LogLevel> nl = mergedLogConfig.get_named_logger_level();
if (nl != null) {
nl.remove(loggerName);
}
break;
default:
// NOOP
break;
}
}
}
LOG.info("Setting log config for {}:{}", topoName, mergedLogConfig);
state.setTopologyLogConfig(topoId, mergedLogConfig, topoConf);
} catch (Exception e) {
LOG.warn("set log config topology exception. (topology id='{}')", topoId, e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
Aggregations