2424import java .util .function .Consumer ;
2525import java .util .regex .Pattern ;
2626
27- import com .vaadin .flow .server .frontend .FrontendUtils ;
28-
2927import org .slf4j .Logger ;
3028import org .slf4j .LoggerFactory ;
3129
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}
0 commit comments