Skip to content

Commit 36307ca

Browse files
authored
fix: Log dev server output using standard logger (#12321)
Rename DevServerOutputFinder to the more descriptive DevServerOutputTracker Fixes #12281
1 parent e791eca commit 36307ca

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

‎flow-test-generic/src/main/java/com/vaadin/flow/testutil/ClassesSerializableTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected Stream<String> getExcludedPatterns() {
6868
".*\\.demo\\..*", "com\\.vaadin\\..*Util(s)?(\\$\\w+)?$",
6969
"com\\.vaadin\\.flow\\.osgi\\.support\\..*",
7070
"com\\.vaadin\\.flow\\.server\\.osgi\\..*",
71-
"com\\.vaadin\\.base\\.devserver\\.DevServerOutputFinder.*",
71+
"com\\.vaadin\\.base\\.devserver\\.DevServerOutputTracker.*",
7272
"com\\.vaadin\\.flow\\.internal\\.VaadinContextInitializer",
7373
"com\\.vaadin\\.flow\\.internal\\.ApplicationClassLoaderAccess",
7474
"com\\.vaadin\\.base\\.devserver\\.BrowserLiveReloadAccessorImpl",

‎vaadin-dev-server/src/main/java/com/vaadin/base/devserver/AbstractDevServerRunner.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import javax.servlet.http.HttpServletRequest;
3838
import javax.servlet.http.HttpServletResponse;
3939

40-
import com.vaadin.base.devserver.DevServerOutputFinder.Result;
40+
import com.vaadin.base.devserver.DevServerOutputTracker.Result;
4141
import com.vaadin.flow.di.Lookup;
4242
import com.vaadin.flow.internal.BrowserLiveReload;
4343
import com.vaadin.flow.internal.BrowserLiveReloadAccessor;
@@ -362,16 +362,16 @@ protected Process doStartDevServer() {
362362
*/
363363
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
364364

365-
DevServerOutputFinder finder = new DevServerOutputFinder(
365+
DevServerOutputTracker outputTracker = new DevServerOutputTracker(
366366
process.getInputStream(), getServerSuccessPattern(),
367367
getServerFailurePattern(), this::onDevServerCompilation);
368-
finder.find();
368+
outputTracker.find();
369369
getLogger().info(LOG_START, getServerName());
370370

371371
int timeout = Integer.parseInt(config.getStringProperty(
372372
InitParameters.SERVLET_PARAMETER_DEVMODE_WEBPACK_TIMEOUT,
373373
DEFAULT_TIMEOUT_FOR_PATTERN));
374-
finder.awaitFirstMatch(timeout);
374+
outputTracker.awaitFirstMatch(timeout);
375375

376376
return process;
377377
} catch (IOException e) {

vaadin-dev-server/src/main/java/com/vaadin/base/devserver/DevServerOutputFinder.java renamed to vaadin-dev-server/src/main/java/com/vaadin/base/devserver/DevServerOutputTracker.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.function.Consumer;
2525
import java.util.regex.Pattern;
2626

27-
import com.vaadin.flow.server.frontend.FrontendUtils;
28-
2927
import org.slf4j.Logger;
3028
import org.slf4j.LoggerFactory;
3129

@@ -35,7 +33,7 @@
3533
* <p>
3634
* Triggers an event whenever a success or failure pattern is found on a row.
3735
*/
38-
public class DevServerOutputFinder {
36+
public class DevServerOutputTracker {
3937

4038
private static class Finder implements Runnable {
4139

@@ -74,7 +72,6 @@ private void readLinesLoop(InputStreamReader reader)
7472
StringBuilder line = new StringBuilder();
7573
for (int i; (i = reader.read()) >= 0;) {
7674
char ch = (char) i;
77-
FrontendUtils.console("%c", ch);
7875
line.append(ch);
7976
if (ch == '\n') {
8077
processLine(line.toString());
@@ -88,11 +85,20 @@ private void processLine(String line) {
8885
if (line.contains("\b")) {
8986
return;
9087
}
91-
92-
// remove color escape codes for console
88+
// remove color escape codes
9389
String cleanLine = line.replaceAll("(\u001b\\[[;\\d]*m|[\b\r]+)",
9490
"");
9591

92+
// Remove newline and timestamp as logger will add it
93+
String logLine = cleanLine;
94+
logLine = logLine.replaceAll("\n$", "");
95+
96+
// Vite preprends a timestamp
97+
logLine = logLine.replaceAll("[0-9]+:[0-9]+:[0-9]+ [AP]M ", "");
98+
// Webpack often prepends with <i>
99+
logLine = logLine.replaceAll("^<i> ", "");
100+
getLogger().info(logLine);
101+
96102
boolean succeed = success != null && success.matcher(line).find();
97103
boolean failed = failure != null && failure.matcher(line).find();
98104

@@ -110,10 +116,6 @@ private void processLine(String line) {
110116
}
111117
}
112118

113-
private static Logger getLogger() {
114-
return LoggerFactory.getLogger(Finder.class);
115-
}
116-
117119
}
118120

119121
/**
@@ -158,7 +160,7 @@ public String getOutput() {
158160
* @param onMatch
159161
* callback triggered when either success or failure is found
160162
*/
161-
public DevServerOutputFinder(InputStream inputStream, Pattern success,
163+
public DevServerOutputTracker(InputStream inputStream, Pattern success,
162164
Pattern failure, Consumer<Result> onMatch) {
163165
monitor = new CountDownLatch(1);
164166
finder = new Finder(inputStream, success, failure, result -> {
@@ -176,7 +178,7 @@ public DevServerOutputFinder(InputStream inputStream, Pattern success,
176178
public void find() {
177179
Thread finderThread = new Thread(finder);
178180
finderThread.setDaemon(true);
179-
finderThread.setName("dev-server-output-reader");
181+
finderThread.setName("dev-server-output");
180182
finderThread.start();
181183
}
182184

@@ -195,4 +197,8 @@ public boolean awaitFirstMatch(int timeoutInSeconds)
195197
return monitor.await(timeoutInSeconds, TimeUnit.SECONDS);
196198
}
197199

200+
private static Logger getLogger() {
201+
return LoggerFactory.getLogger(DevServerOutputTracker.class);
202+
}
203+
198204
}

‎vaadin-dev-server/src/main/java/com/vaadin/base/devserver/WebpackHandler.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.concurrent.CompletableFuture;
2323
import java.util.regex.Pattern;
2424

25-
import com.vaadin.base.devserver.DevServerOutputFinder.Result;
25+
import com.vaadin.base.devserver.DevServerOutputTracker.Result;
2626
import com.vaadin.flow.di.Lookup;
2727
import com.vaadin.flow.server.InitParameters;
2828
import com.vaadin.flow.server.frontend.FrontendUtils;

0 commit comments

Comments
 (0)