Skip to content

Commit 31fac80

Browse files
committed
add IFlowScopeLog interface in LogUtils
This allows a wrapped object to be used as parent scope for the builder. Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
1 parent f42d4d8 commit 31fac80

File tree

1 file changed

+35
-13
lines changed
  • src/main/java/org/eclipse/tracecompass/trace_event_logger

1 file changed

+35
-13
lines changed

src/main/java/org/eclipse/tracecompass/trace_event_logger/LogUtils.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@
118118
*/
119119
public final class LogUtils {
120120

121+
/**
122+
* Interface for flow scope logger
123+
*/
124+
public interface IFlowScopeLog {
125+
126+
/**
127+
* Get the category for this scope. The category can be injected to
128+
* other components that can use it for the scope loggers
129+
*
130+
* @return The category of this scope
131+
*/
132+
String getCategory();
133+
134+
/**
135+
* Get the ID for this scope. The ID can be injected to other components
136+
* that can use it for the scope loggers
137+
*
138+
* @return The ID of this scope
139+
*/
140+
int getId();
141+
}
142+
121143
private static final Format FORMAT = new DecimalFormat("#.###"); //$NON-NLS-1$
122144

123145
/*
@@ -292,7 +314,7 @@ public static class FlowScopeLogBuilder {
292314
private final Object[] fArgs;
293315
private int fId = Integer.MIN_VALUE;
294316
private String fCategory = null;
295-
private FlowScopeLog fParent = null;
317+
private IFlowScopeLog fParent = null;
296318
private boolean fHasParent = false;
297319

298320
/**
@@ -321,7 +343,7 @@ public FlowScopeLogBuilder(Logger logger, Level level, String label, Object... a
321343
* will be automatically generated.
322344
*
323345
* This method is mutually exclusive with
324-
* {@link #setParentScope(FlowScopeLog)}. Calling both will throw an
346+
* {@link #setParentScope(IFlowScopeLog)}. Calling both will throw an
325347
* exception.
326348
*
327349
* @param category
@@ -340,7 +362,7 @@ public FlowScopeLogBuilder setCategory(String category) {
340362
* Set a category and ID for the flow scope.
341363
*
342364
* This method is mutually exclusive with
343-
* {@link #setParentScope(FlowScopeLog)}. Calling both will throw an
365+
* {@link #setParentScope(IFlowScopeLog)}. Calling both will throw an
344366
* exception.
345367
*
346368
* @param category
@@ -373,7 +395,7 @@ public FlowScopeLogBuilder setCategoryAndId(String category, int id) {
373395
* The parent scope
374396
* @return This builder
375397
*/
376-
public FlowScopeLogBuilder setParentScope(FlowScopeLog parent) {
398+
public FlowScopeLogBuilder setParentScope(IFlowScopeLog parent) {
377399
if (fCategory != null) {
378400
throw new IllegalStateException("FlowScopeLogBuilder: Cannot set a parent scope if a category has already been set"); //$NON-NLS-1$
379401
}
@@ -387,10 +409,10 @@ public FlowScopeLogBuilder setParentScope(FlowScopeLog parent) {
387409
* @return The flow scope log
388410
*/
389411
public FlowScopeLog build() {
390-
FlowScopeLog parent = fParent;
412+
IFlowScopeLog parent = fParent;
391413
if (parent != null) {
392414
// Has a parent scope, so step in flow
393-
return new FlowScopeLog(fLogger, fLevel, fLabel, parent.fCategory, parent.fId, false, fArgs);
415+
return new FlowScopeLog(fLogger, fLevel, fLabel, parent.getCategory(), parent.getId(), false, fArgs);
394416
}
395417
return new FlowScopeLog(fLogger, fLevel, fLabel, String.valueOf(fCategory), (fId == Integer.MIN_VALUE ? ID_GENERATOR.incrementAndGet() : fId), !fHasParent, fArgs);
396418
}
@@ -430,7 +452,7 @@ public FlowScopeLog build() {
430452
* INFO: {"ts":"12420,"ph":"f","tid":0,"cat":"category", "id":256}
431453
* }</pre>
432454
*/
433-
public static class FlowScopeLog implements AutoCloseable {
455+
public static class FlowScopeLog implements IFlowScopeLog, AutoCloseable {
434456

435457
private final long fThreadId;
436458
private final Logger fLogger;
@@ -541,12 +563,12 @@ public void addData(String name, Object value) {
541563
fData.put(name, value);
542564
}
543565

544-
/**
545-
* Get the ID for this scope. The ID can be injected to other components
546-
* that can use it for the scope loggers
547-
*
548-
* @return The ID of this scope
549-
*/
566+
@Override
567+
public String getCategory() {
568+
return fCategory;
569+
}
570+
571+
@Override
550572
public int getId() {
551573
return fId;
552574
}

0 commit comments

Comments
 (0)