mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Address dev<Mode log flooding concern raised by Greg Huber
in the Struts Dev List review of 2.5.19. - Introduce a static count-limiter for the devMode set warning in OgnlValueStack. Limit warnings to 250 total, after which it switches to trace level logs to avoid log flooding.
This commit is contained in:
@@ -40,6 +40,7 @@ import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
@@ -61,6 +62,10 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
|
||||
private static final String MAP_IDENTIFIER_KEY = "com.opensymphony.xwork2.util.OgnlValueStack.MAP_IDENTIFIER_KEY";
|
||||
|
||||
private static final int MAX_DEVMODESET_WARNCOUNT = 250;
|
||||
|
||||
private static final AtomicInteger DEVMODESET_WARNCOUNT = new AtomicInteger(0);
|
||||
|
||||
protected CompoundRoot root;
|
||||
protected transient Map<String, Object> context;
|
||||
protected Class defaultType;
|
||||
@@ -105,8 +110,19 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
protected void setDevMode(String mode) {
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
if (this.devMode) {
|
||||
LOG.warn("Setting development mode [{}] affects the safety of your application!",
|
||||
this.devMode);
|
||||
int devModeWarnCount = DEVMODESET_WARNCOUNT.get();
|
||||
if (devModeWarnCount < MAX_DEVMODESET_WARNCOUNT) {
|
||||
devModeWarnCount = DEVMODESET_WARNCOUNT.incrementAndGet();
|
||||
LOG.warn("Setting development mode [{}] affects the safety of your application!",
|
||||
this.devMode);
|
||||
if (devModeWarnCount >= MAX_DEVMODESET_WARNCOUNT) {
|
||||
LOG.warn("Last warning concerning development mode [{}]! These messages will now be trace level only!",
|
||||
this.devMode);
|
||||
}
|
||||
} else {
|
||||
LOG.trace("Setting development mode [{}] affects the safety of your application!",
|
||||
this.devMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user