| 1 |
|
package com.atlassian.core.logging; |
| 2 |
|
|
| 3 |
|
import org.apache.log4j.spi.LoggingEvent; |
| 4 |
|
|
| 5 |
|
import java.util.List; |
| 6 |
|
import java.util.LinkedList; |
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
|
|
|
| 87.9% |
Uncovered Elements: 4 (33) |
Complexity: 13 |
Complexity Density: 0.72 |
|
| 11 |
|
public class ThreadLocalErrorCollection |
| 12 |
|
{ |
| 13 |
|
public static final int DEFAULT_LIMIT =100; |
| 14 |
|
private static ThreadLocal threadLocalCollection = new ThreadLocal(){ |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 15 |
1
|
protected Object initialValue(){... |
| 16 |
1
|
return new LinkedList(); |
| 17 |
|
} |
| 18 |
|
}; |
| 19 |
|
|
| 20 |
|
private static ThreadLocal threadLocalEnabled = new ThreadLocal(){ |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 21 |
0
|
protected Object initialValue(){... |
| 22 |
0
|
return Boolean.FALSE; |
| 23 |
|
} |
| 24 |
|
}; |
| 25 |
|
|
| 26 |
|
private static int limit = DEFAULT_LIMIT; |
| 27 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 28 |
211
|
public static void add(long timeInMillis, LoggingEvent e)... |
| 29 |
|
{ |
| 30 |
211
|
if (!isEnabled()) |
| 31 |
2
|
return; |
| 32 |
|
|
| 33 |
209
|
List loggingEvents = getList(); |
| 34 |
|
|
| 35 |
209
|
loggingEvents.add(new DatedLoggingEvent(timeInMillis, e)); |
| 36 |
|
|
| 37 |
309
|
while (loggingEvents.size() > limit) |
| 38 |
100
|
loggingEvents.remove(0); |
| 39 |
|
|
| 40 |
|
} |
| 41 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 42 |
6
|
public static void clear()... |
| 43 |
|
{ |
| 44 |
6
|
getList().clear(); |
| 45 |
|
} |
| 46 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 47 |
222
|
public static List getList()... |
| 48 |
|
{ |
| 49 |
222
|
List list = (List) threadLocalCollection.get(); |
| 50 |
222
|
return list; |
| 51 |
|
} |
| 52 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
4
|
public static boolean isEmpty()... |
| 54 |
|
{ |
| 55 |
4
|
return getList().isEmpty(); |
| 56 |
|
} |
| 57 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 58 |
0
|
public static int getLimit()... |
| 59 |
|
{ |
| 60 |
0
|
return limit; |
| 61 |
|
} |
| 62 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 63 |
1
|
public static void setLimit(int limit)... |
| 64 |
|
{ |
| 65 |
1
|
ThreadLocalErrorCollection.limit = limit; |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 68 |
211
|
public static boolean isEnabled()... |
| 69 |
|
{ |
| 70 |
211
|
Boolean enabledState = (Boolean) threadLocalEnabled.get(); |
| 71 |
211
|
return Boolean.TRUE.equals(enabledState); |
| 72 |
|
} |
| 73 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
7
|
public static void enable()... |
| 75 |
|
{ |
| 76 |
7
|
threadLocalEnabled.set(Boolean.TRUE); |
| 77 |
|
} |
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 79 |
8
|
public static void disable()... |
| 80 |
|
{ |
| 81 |
8
|
threadLocalEnabled.set(Boolean.FALSE); |
| 82 |
|
} |
| 83 |
|
} |