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.commons;
12  
13  import psiprobe.tools.logging.LogDestination;
14  import psiprobe.tools.logging.jdk.Jdk14LoggerAccessor;
15  import psiprobe.tools.logging.log4j.Log4JLoggerAccessor;
16  
17  /**
18   * The Class GetSingleDestinationVisitor.
19   */
20  public class GetSingleDestinationVisitor extends AbstractLoggerAccessorVisitor {
21  
22    /** The log index. */
23    private final String logIndex;
24  
25    /** The destination. */
26    private LogDestination destination;
27  
28    /**
29     * Instantiates a new gets the single destination visitor.
30     *
31     * @param logIndex the log index
32     */
33    public GetSingleDestinationVisitor(String logIndex) {
34      this.logIndex = logIndex;
35    }
36  
37    /**
38     * Gets the destination.
39     *
40     * @return the destination
41     */
42    public LogDestination getDestination() {
43      return destination;
44    }
45  
46    @Override
47    public void visit(Log4JLoggerAccessor accessor) {
48      LogDestination dest = accessor.getAppender(logIndex);
49      if (dest != null) {
50        destination = dest;
51      }
52    }
53  
54    @Override
55    public void visit(Jdk14LoggerAccessor accessor) {
56      LogDestination dest = accessor.getHandler(logIndex);
57      if (dest != null) {
58        destination = dest;
59      }
60    }
61  
62  }