use of org.apache.storm.generated.LogLevel in project storm by apache.
the class UIHelpers method getTopolgoyLogConfig.
/**
* getTopolgoyLogConfig.
* @param logConfig logConfig
* @return getTopolgoyLogConfig
*/
public static Map<String, Object> getTopolgoyLogConfig(LogConfig logConfig) {
Map<String, Object> result = new HashMap();
if (logConfig.is_set_named_logger_level()) {
for (Map.Entry<String, LogLevel> entry : logConfig.get_named_logger_level().entrySet()) {
Map temp = new HashMap();
temp.put("target_level", entry.getValue().get_target_log_level());
temp.put("reset_level", entry.getValue().get_reset_log_level());
temp.put("timeout", entry.getValue().get_reset_log_level_timeout_secs());
temp.put("timeout_epoch", entry.getValue().get_reset_log_level_timeout_epoch());
result.put(entry.getKey(), temp);
}
}
Map finalResult = new HashMap();
finalResult.put("namedLoggerLevels", result);
return finalResult;
}
use of org.apache.storm.generated.LogLevel in project storm by apache.
the class UIHelpers method putTopologyLogLevel.
/**
* putTopologyLogLevel.
* @param client client
* @param namedLogLevel namedLogLevel
* @param id id
* @return putTopologyLogLevel.
* @throws TException TException
*/
public static Map<String, Object> putTopologyLogLevel(Nimbus.Iface client, Map<String, Map> namedLogLevel, String id) throws TException {
Map<String, Map> namedLoggerlevels = namedLogLevel;
for (Map.Entry<String, Map> entry : namedLoggerlevels.entrySet()) {
String loggerNMame = entry.getKey();
String targetLevel = (String) entry.getValue().get("target_level");
Long timeout = (Long) entry.getValue().get("timeout");
LogLevel logLevel = new LogLevel();
if (targetLevel == null) {
logLevel.set_action(LogLevelAction.REMOVE);
logLevel.unset_target_log_level();
} else {
logLevel.set_action(LogLevelAction.UPDATE);
logLevel.set_target_log_level(org.apache.logging.log4j.Level.toLevel(targetLevel).name());
logLevel.set_reset_log_level_timeout_secs(Math.toIntExact(timeout));
}
LogConfig logConfig = new LogConfig();
logConfig.put_to_named_logger_level(loggerNMame, logLevel);
client.setLogConfig(id, logConfig);
}
return UIHelpers.getTopolgoyLogConfig(client.getLogConfig(id));
}
use of org.apache.storm.generated.LogLevel in project storm by apache.
the class SetLogLevel method main.
public static void main(String[] args) throws Exception {
Map<String, Object> cl = CLI.opt("l", "log-setting", null, new LogLevelsParser(LogLevelAction.UPDATE), CLI.INTO_MAP).opt("r", "remove-log-setting", null, new LogLevelsParser(LogLevelAction.REMOVE), CLI.INTO_MAP).arg("topologyName", CLI.FIRST_WINS).parse(args);
final String topologyName = (String) cl.get("topologyName");
Utils.validateTopologyName(topologyName);
final LogConfig logConfig = new LogConfig();
Map<String, LogLevel> logLevelMap = new HashMap<>();
Map<String, LogLevel> updateLogLevel = (Map<String, LogLevel>) cl.get("l");
if (null != updateLogLevel) {
logLevelMap.putAll(updateLogLevel);
}
Map<String, LogLevel> removeLogLevel = (Map<String, LogLevel>) cl.get("r");
if (null != removeLogLevel) {
logLevelMap.putAll(removeLogLevel);
}
for (Map.Entry<String, LogLevel> entry : logLevelMap.entrySet()) {
logConfig.put_to_named_logger_level(entry.getKey(), entry.getValue());
}
NimbusClient.withConfiguredClient(new NimbusClient.WithNimbus() {
@Override
public void run(Nimbus.Iface nimbus) throws Exception {
String topologyId = Utils.getTopologyId(topologyName, nimbus);
if (null == topologyId) {
throw new IllegalArgumentException(topologyName + " is not a running topology");
}
nimbus.setLogConfig(topologyId, logConfig);
LOG.info("Log config {} is sent for topology {}", logConfig, topologyName);
}
});
}
use of org.apache.storm.generated.LogLevel in project storm by apache.
the class LogConfigManager method resetLogLevels.
// function called on timer to reset log levels last set to DEBUG
// also called from processLogConfigChange
public void resetLogLevels() {
TreeMap<String, LogLevel> latestLogLevelMap = latestLogConfig.get();
LOG.debug("Resetting log levels: Latest log config is {}", latestLogLevelMap);
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
for (String loggerName : latestLogLevelMap.descendingKeySet()) {
LogLevel loggerSetting = latestLogLevelMap.get(loggerName);
long timeout = loggerSetting.get_reset_log_level_timeout_epoch();
String resetLogLevel = loggerSetting.get_reset_log_level();
if (timeout < Time.currentTimeMillis()) {
LOG.info("{}: Resetting level to {}", loggerName, resetLogLevel);
setLoggerLevel(loggerContext, loggerName, resetLogLevel);
latestLogConfig.getAndUpdate(input -> {
TreeMap<String, LogLevel> result = new TreeMap<>(input);
result.remove(loggerName);
return result;
});
}
}
loggerContext.updateLoggers();
}
use of org.apache.storm.generated.LogLevel in project storm by apache.
the class LogConfigManagerTest method ll.
public static LogLevel ll(String target, long epoc) {
LogLevel ret = ll();
ret.set_target_log_level(target);
ret.set_reset_log_level_timeout_epoch(epoc);
return ret;
}
Aggregations