Revision 1088

View differences:

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

  
2

  
3
package org.gvsig.tools.logger;
4

  
5
import org.slf4j.Logger;
6

  
7
public class FilteredLogger {
8
        protected int count = 0;
9
        protected final Logger logger;
10
        protected final int max;
11
        protected String processName;
12
        
13
        public FilteredLogger(Logger logger, String processName, int max) {
14
            this.max = max;
15
            this.logger = logger;
16
            this.processName = processName;
17
            this.count = 0;
18
        }
19

  
20
        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+").");
25
            }
26
            return false;
27
        }
28
                
29
        public void warn(String msg, Throwable th) {
30
            if( canDumpMoreMessages() ) {
31
                this.logger.warn(msg,th);
32
            }
33
        }
34
        
35
        public void warn(String msg) {
36
            if( canDumpMoreMessages() ) {
37
                this.logger.warn(msg);
38
            }
39
        }
40
        
41
        public void info(String msg) {
42
            if( canDumpMoreMessages() ) {
43
                this.logger.info(msg);
44
            }
45
        }
46
}

Also available in: Unified diff