View Javadoc
1   package us.codecraft.webmagic.scripts.config;
2   
3   import java.util.List;
4   
5   import org.apache.commons.lang3.tuple.Pair;
6   import org.apache.logging.log4j.Level;
7   import org.apache.logging.log4j.core.Logger;
8   import org.slf4j.LoggerFactory;
9   
10  public class ConfigLogger {
11      /**
12       * Log the config parameter. If the counter is less than the number of available
13       * options then it means that the user entered an option
14       * 
15       * @param value The config string
16       */
17      public static void configLogger(String value) {
18          List<Pair<String, Level>> options = List.of(
19              Pair.of("debug", Level.DEBUG),
20              Pair.of("info", Level.INFO),
21              Pair.of("warn", Level.WARN),
22              Pair.of("trace", Level.TRACE),
23              Pair.of("off", Level.OFF),
24              Pair.of("error", Level.ERROR));
25          Pair<String, Level> option = options.get(0);
26          int i = 1;
27          while (i < options.size() && !option.getLeft().equalsIgnoreCase(value))
28              option = options.get(i++);
29          if (i < options.size()) {
30              Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
31              rootLogger.setLevel(option.getRight());
32          }
33      }
34  }