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