• 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

36.0
cli/src/main/java/com/devonfw/tools/ide/log/IdeLogExceptionDetails.java
1
package com.devonfw.tools.ide.log;
2

3
import java.io.PrintWriter;
4
import java.io.StringWriter;
5

6
/**
7
 * {@link Enum} with the available details logged for an {@link Throwable error}.
8
 */
9
enum IdeLogExceptionDetails {
3✔
10

11
  /** Log the entire stacktrace. */
12
  STACKTRACE(512) {
13✔
13
    @Override
14
    void format(Throwable error, StringWriter sw) {
15

16
      try (PrintWriter pw = new PrintWriter(sw)) {
×
17
        error.printStackTrace(pw);
×
18
      }
19
    }
×
20
  },
21

22
  /** Log only the exception type and message. */
23
  TO_STRING(32) {
13✔
24
    @Override
25
    void format(Throwable error, StringWriter sw) {
26

27
      sw.append(error.toString());
×
28
    }
×
29
  },
30

31
  /** Log only the message. */
32
  MESSAGE(16) {
13✔
33
    @Override
34
    void format(Throwable error, StringWriter sw) {
35

36
      String errorMessage = error.getMessage();
×
37
      if ((errorMessage == null) || errorMessage.isBlank()) {
×
38
        errorMessage = error.getClass().getName();
×
39
      }
40
      sw.append(errorMessage);
×
41
    }
×
42
  },
43

44
  /** Ignore error and only log explicit message. */
45
  NONE(0) {
13✔
46
    @Override
47
    String format(String message, Throwable error) {
48
      return message;
×
49
    }
50

51
    @Override
52
    void format(Throwable error, StringWriter sw) {
53

54
    }
×
55
  };
56

57
  private final int capacityOffset;
58

59
  private IdeLogExceptionDetails(int capacityOffset) {
4✔
60

61
    this.capacityOffset = capacityOffset;
3✔
62
  }
1✔
63

64
  /**
65
   * @param message the formatted log message.
66
   * @param error the {@link Throwable} to log.
67
   */
68
  String format(String message, Throwable error) {
69

70
    int capacity = this.capacityOffset;
×
71
    if (message != null) {
×
72
      capacity = capacity + message.length() + 1;
×
73
    }
74
    StringWriter sw = new StringWriter(capacity);
×
75
    if (message != null) {
×
76
      sw.append(message);
×
77
      sw.append('\n');
×
78
    }
79
    format(error, sw);
×
80
    return sw.toString();
×
81
  }
82

83
  abstract void format(Throwable error, StringWriter sw);
84

85
  /**
86
   * @param level the {@link IdeLogLevel} of the {@link IdeSubLogger}.
87
   * @param minLogLevel the minimum {@link IdeLogLevel} (threshold).
88
   * @return the {@link IdeLogExceptionDetails}.
89
   */
90
  static IdeLogExceptionDetails of(IdeLogLevel level, IdeLogLevel minLogLevel) {
91

92
    if ((minLogLevel == IdeLogLevel.TRACE) || (minLogLevel == IdeLogLevel.DEBUG)) {
6!
93
      return STACKTRACE;
×
94
    }
95
    return switch (level) {
6✔
96
      case ERROR -> STACKTRACE;
2✔
97
      case WARNING -> TO_STRING;
2✔
98
      default -> MESSAGE;
1✔
99
    };
100
  }
101

102
}
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