1
2
3
4
5
6
7
8
9
10
11 package psiprobe.tools.logging.catalina;
12
13 import java.io.File;
14 import java.nio.file.Path;
15 import java.text.SimpleDateFormat;
16 import java.util.Date;
17
18 import psiprobe.tools.Instruments;
19 import psiprobe.tools.logging.AbstractLogDestination;
20
21
22
23
24 public class CatalinaLoggerAccessor extends AbstractLogDestination {
25
26 @Override
27 public boolean isContext() {
28 return true;
29 }
30
31 @Override
32 public String getName() {
33 return null;
34 }
35
36 @Override
37 public String getLogType() {
38 return "catalina";
39 }
40
41 @Override
42 public File getFile() {
43 String dir = (String) invokeMethod(getTarget(), "getDirectory", null, null);
44 String prefix = (String) invokeMethod(getTarget(), "getPrefix", null, null);
45 String suffix = (String) invokeMethod(getTarget(), "getSuffix", null, null);
46 boolean timestamp = Instruments.getField(getTarget(), "timestamp") != null;
47 String date = timestamp ? new SimpleDateFormat("yyyy-MM-dd").format(new Date()) : "";
48
49 File file =
50 notNull(date, dir, prefix, suffix) ? Path.of(dir, prefix + date + suffix).toFile() : null;
51 if (file != null && !file.isAbsolute()) {
52 return Path.of(System.getProperty("catalina.base"), file.getPath()).toFile();
53 }
54 return file;
55 }
56
57
58
59
60
61
62
63
64 private boolean notNull(String... strings) {
65 for (String string : strings) {
66 if (string == null) {
67 return false;
68 }
69 }
70 return true;
71 }
72
73 }