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

devonfw / IDEasy / 22860792264

09 Mar 2026 03:25PM UTC coverage: 70.268% (-0.2%) from 70.481%
22860792264

push

github

web-flow
#404: #1713: advanced logging (#1714)

Co-authored-by: Kian <adasd>
Co-authored-by: KianRolf <kian.loroff@capgemini.com>
Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
Co-authored-by: jan-vcapgemini <jan-vincent.hoelzle@capgemini.com>

4068 of 6386 branches covered (63.7%)

Branch coverage included in aggregate %.

10604 of 14494 relevant lines covered (73.16%)

3.08 hits per line

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

39.44
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
import java.util.Set;
6

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

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

17
      try (PrintWriter pw = new PrintWriter(sw)) {
5✔
18
        error.printStackTrace(pw);
3✔
19
      }
20
    }
1✔
21
  },
22

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

28
      if (isEmpty(error)) {
×
29
        return;
×
30
      }
31
      sw.append(error.toString());
×
32
    }
×
33
  },
34

35
  /** Log only the message. */
36
  MESSAGE(16) {
13✔
37
    @Override
38
    void format(Throwable error, StringWriter sw) {
39

40
      if (isEmpty(error)) {
×
41
        return;
×
42
      }
43
      String errorMessage = error.getMessage();
×
44
      if ((errorMessage == null) || errorMessage.isBlank()) {
×
45
        if (error instanceof RuntimeException) {
×
46
          return;
×
47
        }
48
        errorMessage = error.getClass().getName();
×
49
      }
50
      sw.append(errorMessage);
×
51
    }
×
52
  },
53

54
  /** Ignore error and only log explicit message. */
55
  NONE(0) {
13✔
56
    @Override
57
    String format(String message, Throwable error) {
58
      return message;
×
59
    }
60

61
    @Override
62
    void format(Throwable error, StringWriter sw) {
63

64
    }
×
65
  };
66

67
  private static final Set<Class<?>> GENERIC_EXCEPTIONS = Set.of(RuntimeException.class, Throwable.class);
5✔
68

69
  private final int capacityOffset;
70

71
  private IdeLogExceptionDetails(int capacityOffset) {
4✔
72

73
    this.capacityOffset = capacityOffset;
3✔
74
  }
1✔
75

76
  /**
77
   * @param message the formatted log message.
78
   * @param error the {@link Throwable} to log.
79
   */
80
  String format(String message, Throwable error) {
81

82
    int capacity = this.capacityOffset;
3✔
83
    if (message != null) {
2!
84
      capacity = capacity + message.length() + 1;
7✔
85
    }
86
    StringWriter sw = new StringWriter(capacity);
5✔
87
    if (message != null) {
2!
88
      sw.append(message);
4✔
89
      sw.append('\n');
4✔
90
    }
91
    format(error, sw);
4✔
92
    return sw.toString();
3✔
93
  }
94

95
  abstract void format(Throwable error, StringWriter sw);
96

97
  /**
98
   * @param level the {@link IdeLogLevel} of the {@link IdeSubLogger}.
99
   * @param minLogLevel the minimum {@link IdeLogLevel} (threshold).
100
   * @return the {@link IdeLogExceptionDetails}.
101
   */
102
  static IdeLogExceptionDetails of(IdeLogLevel level, IdeLogLevel minLogLevel) {
103

104
    if ((minLogLevel == IdeLogLevel.TRACE) || (minLogLevel == IdeLogLevel.DEBUG)) {
6!
105
      return STACKTRACE;
2✔
106
    }
107
    return switch (level) {
×
108
      case ERROR -> STACKTRACE;
×
109
      case WARNING -> TO_STRING;
×
110
      default -> MESSAGE;
×
111
    };
112
  }
113

114
  private static boolean isEmpty(Throwable error) {
115

116
    String message = error.getMessage();
×
117
    if ((message != null) && !message.isEmpty()) {
×
118
      return false;
×
119
    }
120
    // if we have a generic exception with no message, we assume it is only thrown to get the stacktrace
121
    return GENERIC_EXCEPTIONS.contains(error.getClass());
×
122
  }
123

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