1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.rolling;
15
16 import ch.qos.logback.core.FileAppender;
17 import ch.qos.logback.core.rolling.helper.CompressionMode;
18 import ch.qos.logback.core.rolling.helper.FileNamePattern;
19 import ch.qos.logback.core.spi.ContextAwareBase;
20
21
22
23
24
25
26
27 public abstract class RollingPolicyBase extends ContextAwareBase implements RollingPolicy {
28 protected CompressionMode compressionMode = CompressionMode.NONE;
29
30 FileNamePattern fileNamePattern;
31
32 protected String fileNamePatternStr;
33
34 private FileAppender<?> parent;
35
36
37 FileNamePattern zipEntryFileNamePattern;
38 private boolean started;
39
40
41
42
43
44
45
46
47 protected void determineCompressionMode() {
48 if (fileNamePatternStr.endsWith(".gz")) {
49 addInfo("Will use gz compression");
50 compressionMode = CompressionMode.GZ;
51 } else if (fileNamePatternStr.endsWith(".zip")) {
52 addInfo("Will use zip compression");
53 compressionMode = CompressionMode.ZIP;
54 } else {
55 addInfo("No compression will be used");
56 compressionMode = CompressionMode.NONE;
57 }
58 }
59
60 public void setFileNamePattern(String fnp) {
61 fileNamePatternStr = fnp;
62 }
63
64 public String getFileNamePattern() {
65 return fileNamePatternStr;
66 }
67
68 public CompressionMode getCompressionMode() {
69 return compressionMode;
70 }
71
72 public boolean isStarted() {
73 return started;
74 }
75
76 public void start() {
77 started = true;
78 }
79
80 public void stop() {
81 started = false;
82 }
83
84 public void setParent(FileAppender<?> appender) {
85 this.parent = appender;
86 }
87
88 public boolean isParentPrudent() {
89 return parent.isPrudent();
90 }
91
92 public String getParentsRawFileProperty() {
93 return parent.rawFileProperty();
94 }
95 }