Skip to content

Commit f866eb5

Browse files
committed
reduce noisy logs
1 parent 1e984ca commit f866eb5

3 files changed

Lines changed: 77 additions & 26 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/ModelManagerImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ private void replaceCompilationUnit(WFile filename) {
482482

483483
@Override
484484
public Changes syncCompilationUnitContent(WFile filename, String contents) {
485-
WLogger.info("sync contents for " + filename);
485+
WLogger.debug("sync contents for " + filename);
486486
Set<String> oldPackages = declaredPackages(filename);
487487
replaceCompilationUnit(filename, contents, false);
488488
return new Changes(io.vavr.collection.HashSet.of(filename), oldPackages);
@@ -514,10 +514,10 @@ public CompilationUnit replaceCompilationUnitContent(WFile filename, String cont
514514

515515
@Override
516516
public Changes syncCompilationUnit(WFile f) {
517-
WLogger.info("syncCompilationUnit File " + f);
517+
WLogger.debug("syncCompilationUnit File " + f);
518518
Set<String> oldPackages = declaredPackages(f);
519519
replaceCompilationUnit(f);
520-
WLogger.info("replaced file " + f);
520+
WLogger.debug("replaced file " + f);
521521
WurstGui gui = new WurstGuiLogger();
522522
doTypeCheckPartial(gui, ImmutableList.of(f), oldPackages);
523523
return new Changes(io.vavr.collection.HashSet.of(f), oldPackages);
@@ -537,9 +537,9 @@ private CompilationUnit replaceCompilationUnit(WFile filename, String contents,
537537
return existing;
538538
}
539539
// Stale hash cache after remove/move; CU is gone, so reparse.
540-
WLogger.info("CU hash unchanged but model entry missing for " + filename + ", reparsing.");
540+
WLogger.debug("CU hash unchanged but model entry missing for " + filename + ", reparsing.");
541541
} else {
542-
WLogger.info("CU changed. oldHash = " + oldHash + " == " + contents.hashCode());
542+
WLogger.debug("CU changed. oldHash = " + oldHash + " == " + contents.hashCode());
543543
}
544544
}
545545

@@ -552,7 +552,7 @@ private CompilationUnit replaceCompilationUnit(WFile filename, String contents,
552552
fileHashcodes.put(filename, contents.hashCode());
553553
if (reportErrors) {
554554
if (gui.getErrorCount() > 0) {
555-
WLogger.info("found " + gui.getErrorCount() + " errors in file " + filename);
555+
WLogger.debug("found " + gui.getErrorCount() + " errors in file " + filename);
556556
}
557557
ImmutableList.Builder<CompileError> errors = ImmutableList.<CompileError>builder()
558558
.addAll(gui.getErrorsAndWarnings());
@@ -576,7 +576,7 @@ private void clearFileState(WFile file) {
576576
public CompilationUnit getCompilationUnit(WFile filename) {
577577
List<CompilationUnit> matches = getCompilationUnits(Collections.singletonList(filename));
578578
if (matches.isEmpty()) {
579-
WLogger.info("compilation unit not found: " + filename);
579+
WLogger.trace("compilation unit not found: " + filename);
580580
return null;
581581
}
582582
return matches.get(0);
@@ -628,7 +628,7 @@ public void onCompilationResult(Consumer<PublishDiagnosticsParams> f) {
628628
}
629629

630630
private void doTypeCheckPartial(WurstGui gui, List<WFile> toCheckFilenames, Set<String> oldPackages) {
631-
WLogger.info("do typecheck partial of " + toCheckFilenames);
631+
WLogger.debug("do typecheck partial of " + toCheckFilenames);
632632
WurstCompilerJassImpl comp = getCompiler(gui);
633633
List<CompilationUnit> toCheck = getCompilationUnits(toCheckFilenames);
634634

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/WurstLanguageServer.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99

1010
import java.io.FileDescriptor;
1111
import java.io.FileOutputStream;
12+
import java.io.IOException;
13+
import java.io.OutputStream;
1214
import java.io.PrintStream;
1315
import java.nio.charset.StandardCharsets;
1416
import java.util.Arrays;
1517
import java.util.Collections;
1618
import java.util.List;
1719
import java.util.concurrent.CompletableFuture;
20+
import java.util.logging.Level;
21+
import java.util.logging.Logger;
1822

1923
/**
2024
*
@@ -29,7 +33,7 @@ public class WurstLanguageServer implements LanguageServer, LanguageClientAware
2933
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
3034
System.err.println("Loading Wurst version " + CompileTimeInfo.version);
3135
setupLogger();
32-
System.setErr(new PrintStream(new FileOutputStream(FileDescriptor.err), true, StandardCharsets.UTF_8));
36+
System.setErr(createFilteredErr());
3337
if (params.getRootUri() == null) {
3438
System.err.println("Workspace null. Make sure to open a valid project root using File->Open Folder, before opening code files.");
3539
return CompletableFuture.completedFuture(null);
@@ -85,6 +89,53 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
8589
}
8690
private void setupLogger() {
8791
WLogger.setLogger("languageServer");
92+
Logger.getLogger(RemoteEndpoint.class.getName()).setLevel(Level.SEVERE);
93+
Logger.getLogger("org.eclipse.lsp4j.jsonrpc.RemoteEndpoint").setLevel(Level.SEVERE);
94+
}
95+
96+
private PrintStream createFilteredErr() {
97+
PrintStream rawErr = new PrintStream(new FileOutputStream(FileDescriptor.err), true, StandardCharsets.UTF_8);
98+
OutputStream filteringOutput = new OutputStream() {
99+
private final StringBuilder lineBuffer = new StringBuilder();
100+
101+
@Override
102+
public void write(int b) throws IOException {
103+
char c = (char) b;
104+
if (c == '\n') {
105+
flushLine();
106+
rawErr.write('\n');
107+
rawErr.flush();
108+
} else if (c != '\r') {
109+
lineBuffer.append(c);
110+
}
111+
}
112+
113+
@Override
114+
public void flush() throws IOException {
115+
flushLine();
116+
rawErr.flush();
117+
}
118+
119+
private void flushLine() throws IOException {
120+
if (lineBuffer.isEmpty()) {
121+
return;
122+
}
123+
String line = lineBuffer.toString();
124+
lineBuffer.setLength(0);
125+
if (shouldSuppressErrLine(line)) {
126+
return;
127+
}
128+
rawErr.write(line.getBytes(StandardCharsets.UTF_8));
129+
}
130+
};
131+
return new PrintStream(filteringOutput, true, StandardCharsets.UTF_8);
132+
}
133+
134+
private boolean shouldSuppressErrLine(String line) {
135+
return line.startsWith("WARNING: A restricted method in java.lang.System has been called")
136+
|| line.startsWith("WARNING: java.lang.System::load has been called by org.sqlite.SQLiteJDBCLoader")
137+
|| line.startsWith("WARNING: Use --enable-native-access=ALL-UNNAMED")
138+
|| line.startsWith("WARNING: Restricted methods will be blocked in a future release");
88139
}
89140

90141
@Override

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/WurstTextDocumentService.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public WurstTextDocumentService(LanguageWorker worker) {
2626

2727
@Override
2828
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams position) {
29-
WLogger.info("completion");
29+
WLogger.debug("completion");
3030
return worker.handle(new GetCompletions(position, worker.getBufferManager())).thenApply(Either::forRight);
3131
}
3232

3333
@Override
3434
public CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem unresolved) {
35-
WLogger.info("resolveCompletionItem");
35+
WLogger.trace("resolveCompletionItem");
3636
return CompletableFuture.completedFuture(unresolved);
3737
}
3838

@@ -43,37 +43,37 @@ public CompletableFuture<Hover> hover(HoverParams hoverParams) {
4343

4444
@Override
4545
public CompletableFuture<SignatureHelp> signatureHelp(SignatureHelpParams helpParams) {
46-
WLogger.info("signatureHelp");
46+
WLogger.debug("signatureHelp");
4747
return worker.handle(new SignatureInfo(helpParams, worker.getBufferManager()));
4848
}
4949

5050
@Override
5151
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition(DefinitionParams definitionParams) {
52-
WLogger.info("definition");
52+
WLogger.debug("definition");
5353
return worker.handle(new GetDefinition(definitionParams, worker.getBufferManager(), GetDefinition.LookupType.DEFINITION));
5454
}
5555

5656
@Override
5757
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> declaration(DeclarationParams params) {
58-
WLogger.info("declaration");
58+
WLogger.debug("declaration");
5959
return worker.handle(new GetDefinition(params, worker.getBufferManager(), GetDefinition.LookupType.DECLARATION));
6060
}
6161

6262
@Override
6363
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> typeDefinition(TypeDefinitionParams params) {
64-
WLogger.info("typeDefinition");
64+
WLogger.debug("typeDefinition");
6565
return worker.handle(new GetDefinition(params, worker.getBufferManager(), GetDefinition.LookupType.TYPE_DEFINITION));
6666
}
6767

6868
@Override
6969
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> implementation(ImplementationParams params) {
70-
WLogger.info("implementation");
70+
WLogger.debug("implementation");
7171
return worker.handle(new GetDefinition(params, worker.getBufferManager(), GetDefinition.LookupType.IMPLEMENTATION));
7272
}
7373

7474
@Override
7575
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
76-
WLogger.info("references");
76+
WLogger.debug("references");
7777
return worker.handle(new GetUsages(params, worker.getBufferManager(), true))
7878
.thenApply((List<GetUsages.UsagesData> udList) ->
7979
{
@@ -88,7 +88,7 @@ public CompletableFuture<List<? extends Location>> references(ReferenceParams pa
8888

8989
@Override
9090
public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(DocumentHighlightParams highlightParams) {
91-
WLogger.info("documentHighlight");
91+
WLogger.debug("documentHighlight");
9292
return worker.handle(new GetUsages(highlightParams, worker.getBufferManager(), false))
9393
.thenApply((List<GetUsages.UsagesData> udList) ->
9494
{
@@ -123,7 +123,7 @@ public CompletableFuture<CodeLens> resolveCodeLens(CodeLens unresolved) {
123123

124124
@Override
125125
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
126-
WLogger.info("formatting");
126+
WLogger.debug("formatting");
127127

128128
if (worker.modelManager.hasErrors()) {
129129
throw new RequestFailedException(MessageType.Error, "Fix errors in your code before running.\n" + worker.modelManager.getFirstErrorDescription());
@@ -145,44 +145,44 @@ public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormatting
145145

146146
@Override
147147
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
148-
WLogger.info("rangeFormatting");
148+
WLogger.trace("rangeFormatting");
149149
return CompletableFuture.completedFuture(Collections.emptyList());
150150
}
151151

152152
@Override
153153
public CompletableFuture<List<? extends TextEdit>> onTypeFormatting(DocumentOnTypeFormattingParams params) {
154-
WLogger.info("onTypeFormatting");
154+
WLogger.trace("onTypeFormatting");
155155
return CompletableFuture.completedFuture(Collections.emptyList());
156156
}
157157

158158
@Override
159159
public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
160-
WLogger.info("rename");
160+
WLogger.debug("rename");
161161
return worker.handle(new RenameRequest(params, worker.getBufferManager()));
162162
}
163163

164164
@Override
165165
public void didOpen(DidOpenTextDocumentParams params) {
166-
WLogger.info("didOpen");
166+
WLogger.debug("didOpen");
167167
worker.handleOpen(params);
168168
}
169169

170170
@Override
171171
public void didChange(DidChangeTextDocumentParams params) {
172-
WLogger.info("didChange");
172+
WLogger.trace("didChange");
173173
worker.handleChange(params);
174174

175175
}
176176

177177
@Override
178178
public void didClose(DidCloseTextDocumentParams params) {
179-
WLogger.info("didClose");
179+
WLogger.debug("didClose");
180180
worker.handleClose(params);
181181
}
182182

183183
@Override
184184
public void didSave(DidSaveTextDocumentParams params) {
185-
WLogger.info("didSave");
185+
WLogger.debug("didSave");
186186
worker.handleSave(params);
187187
}
188188

0 commit comments

Comments
 (0)