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

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

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

26.98
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 (isBlank(errorMessage)) {
×
38
        errorMessage = error.getClass().getName();
×
39
      }
40
      sw.append(errorMessage);
×
41
    }
×
42
  };
43

44
  private final int capacityOffset;
45

46
  private IdeLogExceptionDetails(int capacityOffset) {
4✔
47

48
    this.capacityOffset = capacityOffset;
3✔
49
  }
1✔
50

51
  /**
52
   * @param message the formatted log message.
53
   * @param error the {@link Throwable} to log.
54
   */
55
  String format(String message, Throwable error) {
56

57
    boolean hasMessage = !isBlank(message);
×
58
    if (error == null) {
×
59
      if (hasMessage) {
×
60
        return message;
×
61
      } else {
62
        return "Internal error: Both message and error is null - nothing to log!";
×
63
      }
64
    }
65
    int capacity = this.capacityOffset;
×
66
    if (hasMessage) {
×
67
      capacity = capacity + message.length() + 1;
×
68
    }
69
    StringWriter sw = new StringWriter(capacity);
×
70
    if (hasMessage) {
×
71
      sw.append(message);
×
72
      sw.append('\n');
×
73
    }
74
    format(error, sw);
×
75
    return sw.toString();
×
76
  }
77

78
  abstract void format(Throwable error, StringWriter sw);
79

80
  private static boolean isBlank(String string) {
81

82
    if ((string == null) || (string.isBlank())) {
×
83
      return true;
×
84
    }
85
    return false;
×
86
  }
87

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

95
    if ((minLogLevel == IdeLogLevel.TRACE) || (minLogLevel == IdeLogLevel.DEBUG)) {
6!
96
      return STACKTRACE;
×
97
    }
98
    switch (level) {
5✔
99
      case ERROR:
100
        return STACKTRACE;
2✔
101
      case WARNING:
102
        return TO_STRING;
2✔
103
      default:
104
        return MESSAGE;
2✔
105
    }
106
  }
107

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