Skip to content

Commit 2050f57

Browse files
authored
Merge pull request #2535 from brown-kaew/fix/string-log-appender-memleak-for-mock
#2530 Fix StringLogAppender leaks for MockHandler
2 parents fdc684e + c84945d commit 2050f57

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

karate-core/src/main/java/com/intuit/karate/Logger.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class Logger {
4848

4949
private boolean appendOnly;
5050

51+
private boolean logOnly;
52+
5153
public void setAppender(LogAppender appender) {
5254
this.appender = appender;
5355
}
@@ -68,6 +70,14 @@ public boolean isAppendOnly() {
6870
return appendOnly;
6971
}
7072

73+
public void setLogOnly(boolean logOnly) {
74+
this.logOnly = logOnly;
75+
}
76+
77+
public boolean isLogOnly() {
78+
return logOnly;
79+
}
80+
7181
public Logger(Class clazz) {
7282
LOGGER = LoggerFactory.getLogger(clazz);
7383
}
@@ -85,7 +95,9 @@ public void trace(String format, Object... arguments) {
8595
if (!appendOnly) {
8696
LOGGER.trace(format, arguments);
8797
}
88-
formatAndAppend(format, arguments);
98+
if (!logOnly) {
99+
formatAndAppend(format, arguments);
100+
}
89101
}
90102
}
91103

@@ -94,7 +106,9 @@ public void debug(String format, Object... arguments) {
94106
if (!appendOnly) {
95107
LOGGER.debug(format, arguments);
96108
}
97-
formatAndAppend(format, arguments);
109+
if (!logOnly) {
110+
formatAndAppend(format, arguments);
111+
}
98112
}
99113
}
100114

@@ -103,7 +117,9 @@ public void info(String format, Object... arguments) {
103117
if (!appendOnly) {
104118
LOGGER.info(format, arguments);
105119
}
106-
formatAndAppend(format, arguments);
120+
if (!logOnly) {
121+
formatAndAppend(format, arguments);
122+
}
107123
}
108124
}
109125

@@ -112,7 +128,9 @@ public void warn(String format, Object... arguments) {
112128
if (!appendOnly) {
113129
LOGGER.warn(format, arguments);
114130
}
115-
formatAndAppend(format, arguments);
131+
if (!logOnly) {
132+
formatAndAppend(format, arguments);
133+
}
116134
}
117135
}
118136

@@ -121,7 +139,9 @@ public void error(String format, Object... arguments) {
121139
if (!appendOnly) {
122140
LOGGER.error(format, arguments);
123141
}
124-
formatAndAppend(format, arguments);
142+
if (!logOnly) {
143+
formatAndAppend(format, arguments);
144+
}
125145
}
126146
}
127147

karate-core/src/main/java/com/intuit/karate/core/MockHandler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ private ScenarioRuntime initRuntime(Feature feature, Map<String, Object> args) {
119119
section.setIndex(-1); // TODO util for creating dummy scenario
120120
Scenario dummy = new Scenario(feature, section, -1);
121121
section.setScenario(dummy);
122-
ScenarioRuntime runtime = new ScenarioRuntime(featureRuntime, dummy);
122+
ScenarioRuntime runtime = new ScenarioRuntime(featureRuntime, dummy);
123+
runtime.logger.setLogOnly(true);
123124
runtime.engine.setVariable(PATH_MATCHES, (Function<String, Boolean>) this::pathMatches);
124125
runtime.engine.setVariable(PARAM_EXISTS, (Function<String, Boolean>) this::paramExists);
125126
runtime.engine.setVariable(PARAM_VALUE, (Function<String, String>) this::paramValue);

0 commit comments

Comments
 (0)