Revision 2001 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/logger/FilteredLogger.java

View differences:

FilteredLogger.java
9 9
        protected final Logger logger;
10 10
        protected final int max;
11 11
        protected String processName;
12
        protected long interval;
13
        protected long lastTime;
14
        protected boolean showTooManyErrorsMessage;
12 15
        
13 16
        public FilteredLogger(Logger logger, String processName, int max) {
14 17
            this.max = max;
15 18
            this.logger = logger;
16 19
            this.processName = processName;
17 20
            this.count = 0;
21
            this.interval = -1;
22
            this.lastTime = -1;
23
            this.showTooManyErrorsMessage = false;
18 24
        }
25
        
26
        public void setInterval(long interval) {
27
            this.interval = interval;
28
        }
19 29

  
20 30
        protected boolean canDumpMoreMessages() {
21
            if( ++this.count < this.max ) {
22
                return true;
23
            } else if( this.count == this.max ) {
24
                this.logger.info("Too many errors, don't dump more in this process ("+processName+").");
31
            if( interval>0 ) {
32
                long now = System.currentTimeMillis();
33
                if( this.lastTime < 0 ) {
34
                    this.lastTime = now;
35
                    this.showTooManyErrorsMessage = true;
36
                    return true;
37
                }
38
                if( this.lastTime+this.interval > now ) {
39
                    this.lastTime = now;
40
                    this.showTooManyErrorsMessage = true;
41
                    return true;
42
                }
43
                if( this.showTooManyErrorsMessage ) {
44
                    this.logger.info("Too many errors, skip some in this process ("+processName+").");
45
                    this.showTooManyErrorsMessage = false;
46
                }
47
                return false;
48
            } else {
49
                if( ++this.count < this.max ) {
50
                    return true;
51
                } else if( this.count == this.max ) {
52
                    this.logger.info("Too many errors, don't dump more in this process ("+processName+").");
53
                }
54
                return false;
25 55
            }
26
            return false;
27 56
        }
28 57
                
29 58
        public void warn(String msg, Throwable th) {

Also available in: Unified diff