• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 11963246771

21 Nov 2024 11:10PM UTC coverage: 67.428% (+0.2%) from 67.239%
11963246771

push

github

web-flow
#754: bullet proof solution for processable output and logging (#777)

2487 of 4028 branches covered (61.74%)

Branch coverage included in aggregate %.

6454 of 9232 relevant lines covered (69.91%)

3.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.47
cli/src/main/java/com/devonfw/tools/ide/log/IdeSubLoggerOut.java
1
package com.devonfw.tools.ide.log;
2

3
import java.io.IOException;
4

5
/**
6
 * Default implementation of {@link IdeSubLogger} that can write to an {@link Appendable} such as {@link System#out} or in case of testing a
7
 * {@link java.io.StringWriter}.
8
 */
9
public class IdeSubLoggerOut extends AbstractIdeSubLogger {
10

11
  private final Appendable out;
12

13
  /**
14
   * The constructor.
15
   *
16
   * @param level the {@link #getLevel() log-level}.
17
   * @param out the {@link Appendable} to {@link Appendable#append(CharSequence) write} log messages to.
18
   * @param colored - {@code true} for colored output according to {@link IdeLogLevel}, {@code false} otherwise.
19
   * @param minLogLevel the minimum log level (threshold).
20
   */
21
  public IdeSubLoggerOut(IdeLogLevel level, Appendable out, boolean colored, IdeLogLevel minLogLevel, IdeLogListener listener) {
22

23
    super(level, colored, IdeLogExceptionDetails.of(level, minLogLevel), listener);
8✔
24
    if (out == null) {
2!
25
      // this is on of the very rare excuses where System.out or System.err is allowed to be used!
26
      if (level == IdeLogLevel.ERROR) {
3✔
27
        this.out = System.err;
4✔
28
      } else {
29
        this.out = System.out;
4✔
30
      }
31
    } else {
32
      this.out = out;
×
33
    }
34
  }
1✔
35

36
  @Override
37
  public void doLog(String message, Throwable error) {
38

39
    try {
40
      String startColor = null;
×
41
      if (this.colored) {
×
42
        startColor = this.level.getStartColor();
×
43
        if (startColor != null) {
×
44
          this.out.append(startColor);
×
45
        }
46
      }
47
      if (error != null) {
×
48
        message = this.exceptionDetails.format(message, error);
×
49
      }
50
      this.out.append(message);
×
51
      if (startColor != null) {
×
52
        this.out.append(this.level.getEndColor());
×
53
      }
54
      this.out.append("\n");
×
55
    } catch (IOException e) {
×
56
      throw new IllegalStateException("Failed to log message: " + message, e);
×
57
    }
×
58
  }
×
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc