Search in sources :

Example 1 with LogLevel

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;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel)

Example 2 with LogLevel

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));
}
Also used : Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel) LogConfig(org.apache.storm.generated.LogConfig)

Example 3 with LogLevel

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);
        }
    });
}
Also used : HashMap(java.util.HashMap) NimbusClient(org.apache.storm.utils.NimbusClient) LogLevel(org.apache.storm.generated.LogLevel) Nimbus(org.apache.storm.generated.Nimbus) Map(java.util.Map) HashMap(java.util.HashMap) LogConfig(org.apache.storm.generated.LogConfig)

Example 4 with LogLevel

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();
}
Also used : TreeMap(java.util.TreeMap) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LogLevel(org.apache.storm.generated.LogLevel)

Example 5 with LogLevel

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;
}
Also used : LogLevel(org.apache.storm.generated.LogLevel)

Aggregations

LogLevel (org.apache.storm.generated.LogLevel)17 TreeMap (java.util.TreeMap)10 Test (org.junit.Test)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 LogConfig (org.apache.storm.generated.LogConfig)6 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)6 Map (java.util.Map)5 Mockito.anyString (org.mockito.Mockito.anyString)5 HashMap (java.util.HashMap)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 NavigableMap (java.util.NavigableMap)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 LogLevelAction (org.apache.storm.generated.LogLevelAction)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 TreeSet (java.util.TreeSet)1 IStormClusterState (org.apache.storm.cluster.IStormClusterState)1 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1