Skip to content

Commit

Permalink
refactor doLog function to output level based stdout and stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
alfeilex committed Dec 17, 2024
1 parent ffd6ced commit 4c5f98a
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import com.devonfw.tools.ide.cli.CliProcessException;
import com.devonfw.tools.ide.context.IdeContext;
Expand Down Expand Up @@ -72,7 +71,7 @@ public List<String> getErr() {
@Override
public List<OutputMessage> getOutputMessages() {

return outputMessages;
return this.outputMessages;

}

Expand All @@ -85,18 +84,22 @@ public void log(IdeLogLevel level, IdeContext context) {
public void log(IdeLogLevel outLevel, IdeContext context, IdeLogLevel errorLevel) {

if (!this.outputMessages.isEmpty()) {
doLog(outLevel, getOutputMessages().stream().map(OutputMessage::message).collect(Collectors.toList()), context);
for (OutputMessage outputMessage : this.outputMessages) {
if (outputMessage.error()) {
doLog(errorLevel, outputMessage.message(), context);
} else {
doLog(outLevel, outputMessage.message(), context);
}
}
}
}

private void doLog(IdeLogLevel level, List<String> lines, IdeContext context) {
for (String line : lines) {
// remove !MESSAGE from log message
if (line.startsWith("!MESSAGE ")) {
line = line.substring(9);
}
context.level(level).log(line);
private void doLog(IdeLogLevel level, String message, IdeContext context) {
// remove !MESSAGE from log message
if (message.startsWith("!MESSAGE ")) {
message = message.substring(9);
}
context.level(level).log(message);
}

@Override
Expand Down

0 comments on commit 4c5f98a

Please sign in to comment.