1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.rolling;
19
20 import org.apache.log4j.Appender;
21 import org.apache.log4j.spi.LoggingEvent;
22 import org.apache.log4j.spi.OptionHandler;
23
24
25 /***
26 * SizeBasedTriggeringPolicy looks at size of the file being
27 * currently written to.
28 *
29 * @author Ceki Gülcü
30 * @author Curt Arnold
31 *
32 */
33 public final class SizeBasedTriggeringPolicy implements TriggeringPolicy,
34 OptionHandler {
35 /***
36 * Rollover threshold size in bytes.
37 */
38 private long maxFileSize = 10 * 1024 * 1024;
39
40 /***
41 * Constructs a new instance.
42 */
43 public SizeBasedTriggeringPolicy() {
44 }
45
46 /***
47 * Constructs an new instance.
48 * @param maxFileSize rollover threshold size in bytes.
49 */
50 public SizeBasedTriggeringPolicy(final long maxFileSize) {
51 this.maxFileSize = maxFileSize;
52 }
53
54 /***
55 * {@inheritDoc}
56 */
57 public boolean isTriggeringEvent(
58 final Appender appender, final LoggingEvent event, final String file,
59 final long fileLength) {
60
61 return (fileLength >= maxFileSize);
62 }
63
64 /***
65 * Gets rollover threshold size in bytes.
66 * @return rollover threshold size in bytes.
67 */
68 public long getMaxFileSize() {
69 return maxFileSize;
70 }
71
72 /***
73 * Sets rollover threshold size in bytes.
74 * @param l new value for rollover threshold size.
75 */
76 public void setMaxFileSize(long l) {
77 maxFileSize = l;
78 }
79
80 /***
81 * Prepares policy for use.
82 */
83 public void activateOptions() {
84 }
85 }