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