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;
12  
13  import java.io.File;
14  import java.nio.file.Path;
15  import java.sql.Timestamp;
16  
17  /**
18   * The Class AbstractLogDestination.
19   */
20  public abstract class AbstractLogDestination extends DefaultAccessor implements LogDestination {
21  
22    @Override
23    public boolean isRoot() {
24      return false;
25    }
26  
27    @Override
28    public boolean isContext() {
29      return false;
30    }
31  
32    @Override
33    public String getIndex() {
34      return null;
35    }
36  
37    @Override
38    public String getConversionPattern() {
39      return null;
40    }
41  
42    /**
43     * Gets the stdout file.
44     *
45     * @return the stdout file
46     */
47    protected File getStdoutFile() {
48      File file = Path.of(System.getProperty("catalina.base"), "logs/catalina.out").toFile();
49      return file.exists() ? file : Path.of("stdout").toFile();
50    }
51  
52    @Override
53    public File getFile() {
54      return getStdoutFile();
55    }
56  
57    @Override
58    public long getSize() {
59      File file = getFile();
60      return file != null && file.exists() ? file.length() : 0;
61    }
62  
63    @Override
64    public Timestamp getLastModified() {
65      File file = getFile();
66      return file != null && file.exists() ? new Timestamp(file.lastModified()) : null;
67    }
68  
69    @Override
70    public String getLevel() {
71      return null;
72    }
73  
74    @Override
75    public String[] getValidLevels() {
76      return new String[0];
77    }
78  
79    @Override
80    public String getEncoding() {
81      return null;
82    }
83  }