Search in sources :

Example 1 with LogLevel

use of org.apache.geode.internal.logging.log4j.LogLevel in project geode by apache.

the class ChangeLogLevelFunction method execute.

@Override
public void execute(FunctionContext context) {
    Cache cache = CacheFactory.getAnyInstance();
    Map<String, String> result = new HashMap<String, String>();
    try {
        LogWriterLogger logwriterLogger = (LogWriterLogger) cache.getLogger();
        Object[] args = (Object[]) context.getArguments();
        final String logLevel = (String) args[0];
        Level log4jLevel = LogLevel.getLevel(logLevel);
        logwriterLogger.setLevel(log4jLevel);
        System.setProperty(DistributionConfig.GEMFIRE_PREFIX + LOG_LEVEL, logLevel);
        // LOG:CONFIG:
        logger.info(LogMarker.CONFIG, "GFSH Changed log level to {}", log4jLevel);
        result.put(cache.getDistributedSystem().getDistributedMember().getId(), "New log level is " + log4jLevel);
        context.getResultSender().lastResult(result);
    } catch (Exception ex) {
        // LOG:CONFIG:
        logger.info(LogMarker.CONFIG, "GFSH Changing log level exception {}", ex.getMessage(), ex);
        result.put(cache.getDistributedSystem().getDistributedMember().getId(), "ChangeLogLevelFunction exception " + ex.getMessage());
        context.getResultSender().lastResult(result);
    }
}
Also used : HashMap(java.util.HashMap) Level(org.apache.logging.log4j.Level) LogLevel(org.apache.geode.internal.logging.log4j.LogLevel) Cache(org.apache.geode.cache.Cache) LogWriterLogger(org.apache.geode.internal.logging.log4j.LogWriterLogger)

Aggregations

HashMap (java.util.HashMap)1 Cache (org.apache.geode.cache.Cache)1 LogLevel (org.apache.geode.internal.logging.log4j.LogLevel)1 LogWriterLogger (org.apache.geode.internal.logging.log4j.LogWriterLogger)1 Level (org.apache.logging.log4j.Level)1