Skip to content

Commit

Permalink
fix: Log dev server output using standard logger
Browse files Browse the repository at this point in the history
Fixes #12281
  • Loading branch information
Artur- committed Nov 9, 2021
1 parent e3270bc commit 11237f7
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.function.Consumer;
import java.util.regex.Pattern;

import com.vaadin.flow.server.frontend.FrontendUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -74,7 +72,6 @@ private void readLinesLoop(InputStreamReader reader)
StringBuilder line = new StringBuilder();
for (int i; (i = reader.read()) >= 0;) {
char ch = (char) i;
FrontendUtils.console("%c", ch);
line.append(ch);
if (ch == '\n') {
processLine(line.toString());
Expand All @@ -88,11 +85,20 @@ private void processLine(String line) {
if (line.contains("\b")) {
return;
}

// remove color escape codes for console
// remove color escape codes
String cleanLine = line.replaceAll("(\u001b\\[[;\\d]*m|[\b\r]+)",
"");

// Remove newline and timestamp as logger will add it
String logLine = cleanLine;
logLine = logLine.replaceAll("\n$", "");

// Vite preprends a timestamp
logLine = logLine.replaceAll("[0-9]+:[0-9]+:[0-9]+ [AP]M ", "");
// Webpack often prepends with <i>
logLine = logLine.replaceAll("^<i> ", "");
getLogger().info(logLine);

boolean succeed = success != null && success.matcher(line).find();
boolean failed = failure != null && failure.matcher(line).find();

Expand All @@ -110,10 +116,6 @@ private void processLine(String line) {
}
}

private static Logger getLogger() {
return LoggerFactory.getLogger(Finder.class);
}

}

/**
Expand Down Expand Up @@ -176,7 +178,7 @@ public DevServerOutputTracker(InputStream inputStream, Pattern success,
public void find() {
Thread finderThread = new Thread(finder);
finderThread.setDaemon(true);
finderThread.setName("dev-server-output-reader");
finderThread.setName("dev-server-output");
finderThread.start();
}

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

private static Logger getLogger() {
return LoggerFactory.getLogger(DevServerOutputTracker.class);
}

}

0 comments on commit 11237f7

Please sign in to comment.