1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.slf4j;
20
21 import java.util.concurrent.atomic.AtomicReference;
22
23 import org.apache.maven.logging.api.LogLevelRecorder;
24
25
26
27
28 public class DefaultLogLevelRecorder implements LogLevelRecorder {
29 private Level maxAllowed;
30 private final AtomicReference<Level> maxReached = new AtomicReference<>(Level.DEBUG);
31
32 @Override
33 public boolean hasReachedMaxLevel() {
34 return maxReached.get().ordinal() > maxAllowed.ordinal();
35 }
36
37 @Override
38 public Level getMaxLevelReached() {
39 return maxReached.get();
40 }
41
42 @Override
43 public Level getMaxLevelAllowed() {
44 return maxAllowed;
45 }
46
47 @Override
48 public void setMaxLevelAllowed(Level level) {
49 this.maxAllowed = level;
50 }
51
52 @Override
53 public void reset() {
54 this.maxAllowed = null;
55 this.maxReached.set(Level.DEBUG);
56 }
57
58 public void record(org.slf4j.event.Level logLevel) {
59 Level level =
60 switch (logLevel) {
61 case TRACE, DEBUG -> Level.DEBUG;
62 case INFO -> Level.INFO;
63 case WARN -> Level.WARN;
64 case ERROR -> Level.ERROR;
65 };
66 while (true) {
67 Level r = maxReached.get();
68 if (level.ordinal() > r.ordinal()) {
69 if (!maxReached.compareAndSet(r, level)) {
70 continue;
71 }
72 }
73 break;
74 }
75 }
76
77 public boolean metThreshold() {
78 return maxAllowed != null && maxReached.get().ordinal() >= maxAllowed.ordinal();
79 }
80 }