View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.tools.logging.log4j2;
12  
13  import java.util.Map;
14  
15  import psiprobe.tools.logging.DefaultAccessor;
16  
17  /**
18   * The Class Log4J2LoggerContextAccessor.
19   */
20  public class Log4J2LoggerContextAccessor extends DefaultAccessor {
21  
22    /**
23     * Gets the loggers.
24     *
25     * @return the loggers
26     */
27    public Map<String, Object> getLoggers() {
28      Map<String, Object> loggers = null;
29      Object configuration = null;
30      try {
31        configuration = invokeMethod(getTarget(), "getConfiguration", null, null);
32      } catch (Exception e) {
33        logger.error("exception invoking getConfiguration", e);
34        throw e;
35      }
36      if (configuration != null) {
37        try {
38          loggers = (Map<String, Object>) invokeMethod(configuration, "getLoggers", null, null);
39        } catch (Exception e) {
40          logger.error("exception invoking getLoggers", e);
41          throw e;
42        }
43      }
44      return loggers;
45    }
46  
47    /**
48     * Update log4j2 loggers.
49     */
50    public void updateLoggers() {
51      try {
52        invokeMethod(getTarget(), "updateLoggers", null, null);
53      } catch (Exception e) {
54        logger.error("exception invoking updateLoggers", e);
55        throw e;
56      }
57    }
58  }