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

devonfw / IDEasy / 22303886886

23 Feb 2026 11:19AM UTC coverage: 70.647% (+0.2%) from 70.474%
22303886886

Pull #1714

github

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

4069 of 6360 branches covered (63.98%)

Branch coverage included in aggregate %.

10644 of 14466 relevant lines covered (73.58%)

3.1 hits per line

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

94.12
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

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

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

18
  protected final List<IdeLogEntry> buffer;
19

20
  protected IdeLogLevel threshold;
21

22
  private boolean buffering;
23

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

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

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

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

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

61
    // disable buffering further log events
62
    this.buffering = false;
3✔
63
    // write all cached log events to the logger again for processing
64
    for (IdeLogEntry entry : this.buffer) {
11✔
65
      IdeLogLevel level = entry.level();
3✔
66
      level.log(LOG, entry.error(), entry.rawMessage(), entry.args());
9✔
67
    }
1✔
68
    this.buffer.clear();
3✔
69
    this.threshold = IdeLogLevel.TRACE;
3✔
70
  }
1✔
71

72
  /**
73
   * Re-enables the buffering of the logger so nothing gets logged and log messages are only collected until {@link #flushAndEndBuffering()} is called.
74
   *
75
   * @param threshold the {@link IdeLogLevel} acting as threshold.
76
   * @see com.devonfw.tools.ide.context.IdeContext#runWithoutLogging(Runnable, IdeLogLevel)
77
   */
78
  public void startBuffering(IdeLogLevel threshold) {
79

80
    assert (!this.buffering);
4!
81
    this.threshold = threshold;
3✔
82
    this.buffering = true;
3✔
83
  }
1✔
84

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