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

devonfw / IDEasy / 15251366887

26 May 2025 10:14AM UTC coverage: 67.719% (+0.2%) from 67.562%
15251366887

push

github

web-flow
#1314: add IdeContext.runWithoutLogging to temporary disable logging (#1318)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>

3162 of 5068 branches covered (62.39%)

Branch coverage included in aggregate %.

8082 of 11536 relevant lines covered (70.06%)

3.07 hits per line

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

93.94
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
/**
7
 * Implements {@link IdeLogListener} to buffer log events during bootstrapping and then flush them once the logger is properly configured.
8
 *
9
 * @see com.devonfw.tools.ide.context.IdeContext#runWithoutLogging(Runnable)
10
 */
11
public class IdeLogListenerBuffer implements IdeLogListener {
1✔
12

13
  protected final List<IdeLogEntry> buffer;
14

15
  protected IdeLogLevel threshold;
16

17
  private boolean buffering;
18

19
  /**
20
   * The constructor.
21
   */
22
  public IdeLogListenerBuffer() {
23
    this(true);
3✔
24
  }
1✔
25

26
  IdeLogListenerBuffer(boolean buffering) {
27
    super();
2✔
28
    this.buffer = new ArrayList<>();
5✔
29
    this.threshold = IdeLogLevel.TRACE;
3✔
30
    this.buffering = buffering;
3✔
31
  }
1✔
32

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

44
  /**
45
   * @return {@code true} if this collector is currently buffering all logs, {@code false} otherwise (regular logging).
46
   */
47
  protected boolean isBuffering() {
48
    return this.buffering;
×
49
  }
50

51
  /**
52
   * This method is supposed to be called once after the {@link IdeLogger} has been properly initialized or after invocation of
53
   * {@link #startBuffering(IdeLogLevel)}.
54
   *
55
   * @param logger the initialized {@link IdeLogger}.
56
   */
57
  public void flushAndEndBuffering(IdeLogger logger) {
58

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

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

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

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