1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.rolling;
15
16 import java.io.File;
17
18 import ch.qos.logback.core.util.Duration;
19 import ch.qos.logback.core.util.FileSize;
20 import ch.qos.logback.core.util.DefaultInvocationGate;
21 import ch.qos.logback.core.util.InvocationGate;
22 import ch.qos.logback.core.util.SimpleInvocationGate;
23
24
25
26
27
28
29
30
31
32
33
34
35 public class SizeBasedTriggeringPolicy<E> extends TriggeringPolicyBase<E> {
36
37 public static final String SEE_SIZE_FORMAT = "http://logback.qos.ch/codes.html#sbtp_size_format";
38
39
40
41 public static final long DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
42
43 FileSize maxFileSize = new FileSize(DEFAULT_MAX_FILE_SIZE);
44 InvocationGate invocationGate = new SimpleInvocationGate();
45 Duration checkIncrement = null;
46
47 public SizeBasedTriggeringPolicy() {
48 }
49
50 public void start() {
51 if(checkIncrement != null)
52 invocationGate = new SimpleInvocationGate(checkIncrement);
53 super.start();
54 }
55
56
57 public boolean isTriggeringEvent(final File activeFile, final E event) {
58 long now = System.currentTimeMillis();
59 if (invocationGate.isTooSoon(now))
60 return false;
61
62 return (activeFile.length() >= maxFileSize.getSize());
63 }
64
65 public FileSize getMaxFileSize() {
66 return this.maxFileSize;
67 }
68
69 public void setMaxFileSize(FileSize aMaxFileSize) {
70 this.maxFileSize = aMaxFileSize;
71 }
72
73 public Duration getCheckIncrement() {
74 return checkIncrement;
75 }
76
77 public void setCheckIncrement(Duration checkIncrement) {
78 this.checkIncrement = checkIncrement;
79 }
80 }