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