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.log4j;
12  
13  import java.io.File;
14  
15  import psiprobe.tools.logging.AbstractLogDestination;
16  
17  /**
18   * The Class Log4JAppenderAccessor.
19   */
20  public class Log4JAppenderAccessor extends AbstractLogDestination {
21  
22    /** The logger accessor. */
23    private Log4JLoggerAccessor loggerAccessor;
24  
25    /**
26     * Gets the logger accessor.
27     *
28     * @return the logger accessor
29     */
30    public Log4JLoggerAccessor getLoggerAccessor() {
31      return loggerAccessor;
32    }
33  
34    /**
35     * Sets the logger accessor.
36     *
37     * @param loggerAccessor the new logger accessor
38     */
39    public void setLoggerAccessor(Log4JLoggerAccessor loggerAccessor) {
40      this.loggerAccessor = loggerAccessor;
41    }
42  
43    @Override
44    public boolean isContext() {
45      return getLoggerAccessor().isContext();
46    }
47  
48    @Override
49    public boolean isRoot() {
50      return getLoggerAccessor().isRoot();
51    }
52  
53    @Override
54    public String getName() {
55      return getLoggerAccessor().getName();
56    }
57  
58    @Override
59    public String getLogType() {
60      return "log4j";
61    }
62  
63    @Override
64    public String getIndex() {
65      return (String) getProperty(getTarget(), "name", null);
66    }
67  
68    @Override
69    public String getConversionPattern() {
70      Object layout = getProperty(getTarget(), "layout", null);
71      if (layout != null && "org.apache.log4j.PatternLayout".equals(layout.getClass().getName())) {
72        return (String) getProperty(layout, "conversionPattern", null);
73      }
74      return null;
75    }
76  
77    @Override
78    public File getFile() {
79      String fileName = (String) getProperty(getTarget(), "file", null);
80      return fileName != null ? new File(fileName) : getStdoutFile();
81    }
82  
83    @Override
84    public String getLevel() {
85      return getLoggerAccessor().getLevel();
86    }
87  
88    @Override
89    public String[] getValidLevels() {
90      return new String[] {"OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "ALL"};
91    }
92  
93  }