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

devonfw / IDEasy / 22300285724

23 Feb 2026 09:32AM UTC coverage: 70.754% (+0.3%) from 70.474%
22300285724

Pull #1714

github

web-flow
Merge caa980897 into 379acdc9d
Pull Request #1714: #404: #1713: advanced logging

4064 of 6348 branches covered (64.02%)

Branch coverage included in aggregate %.

10640 of 14434 relevant lines covered (73.71%)

3.1 hits per line

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

95.56
cli/src/main/java/com/devonfw/tools/ide/log/IdeLogListenerBuffer.java
1
package com.devonfw.tools.ide.log;
2

3
import java.util.ArrayList;
4
import java.util.List;
5

6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8
import org.slf4j.Marker;
9
import org.slf4j.spi.LoggingEventBuilder;
10

11
/**
12
 * Implements {@link IdeLogListener} to buffer log events during bootstrapping and then flush them once the logger is properly configured.
13
 *
14
 * @see com.devonfw.tools.ide.context.IdeContext#runWithoutLogging(Runnable)
15
 */
16
public class IdeLogListenerBuffer implements IdeLogListener {
17

18
  private static final Logger LOG = LoggerFactory.getLogger(IdeLogListenerBuffer.class);
4✔
19

20
  protected final List<IdeLogEntry> buffer;
21

22
  protected IdeLogLevel threshold;
23

24
  private boolean buffering;
25

26
  /**
27
   * The constructor.
28
   */
29
  public IdeLogListenerBuffer() {
30
    this(true);
3✔
31
  }
1✔
32

33
  IdeLogListenerBuffer(boolean buffering) {
34
    super();
2✔
35
    this.buffer = new ArrayList<>();
5✔
36
    this.threshold = IdeLogLevel.TRACE;
3✔
37
    this.buffering = buffering;
3✔
38
  }
1✔
39

40
  @Override
41
  public boolean onLog(IdeLogLevel level, String message, String rawMessage, Object[] args, Throwable error) {
42
    if (this.buffering) {
3✔
43
      if (level.ordinal() >= threshold.ordinal()) {
6✔
44
        this.buffer.add(new IdeLogEntry(level, message, rawMessage, args, error));
12✔
45
      }
46
      return false;
2✔
47
    }
48
    return true;
2✔
49
  }
50

51
  /**
52
   * @return {@code true} if this collector is currently buffering all logs, {@code false} otherwise (regular logging).
53
   */
54
  protected boolean isBuffering() {
55
    return this.buffering;
×
56
  }
57

58
  /**
59
   * This method is supposed to be called once after invocation of {@link #startBuffering(IdeLogLevel)}.
60
   */
61
  public void flushAndEndBuffering() {
62

63
    // disable buffering further log events
64
    this.buffering = false;
3✔
65
    // write all cached log events to the logger again for processing
66
    for (IdeLogEntry entry : this.buffer) {
11✔
67
      IdeLogLevel level = entry.level();
3✔
68
      LoggingEventBuilder builder = LOG.atLevel(level.getSlf4jLevel());
5✔
69
      Marker marker = level.getSlf4jMarker();
3✔
70
      if (marker != null) {
2✔
71
        builder = builder.addMarker(marker);
4✔
72
      }
73
      builder = builder.setCause(entry.error());
5✔
74
      if (entry.args() != null) {
3✔
75
        builder.log(entry.rawMessage(), entry.args());
7✔
76
      } else {
77
        builder.log(entry.rawMessage());
4✔
78
      }
79
    }
1✔
80
    this.buffer.clear();
3✔
81
    this.threshold = IdeLogLevel.TRACE;
3✔
82
  }
1✔
83

84
  /**
85
   * Re-enables the buffering of the logger so nothing gets logged and log messages are only collected until {@link #flushAndEndBuffering()} is called.
86
   *
87
   * @param threshold the {@link IdeLogLevel} acting as threshold.
88
   * @see com.devonfw.tools.ide.context.IdeContext#runWithoutLogging(Runnable, IdeLogLevel)
89
   */
90
  public void startBuffering(IdeLogLevel threshold) {
91

92
    assert (!this.buffering);
4!
93
    this.threshold = threshold;
3✔
94
    this.buffering = true;
3✔
95
  }
1✔
96

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