Skip to content

Commit d0d6252

Browse files
authored
Merge pull request #1096 from oracle/pmackin-OWLS-72195
pmackin-OWLS-72195
2 parents 8a95684 + c2f1004 commit d0d6252

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

operator/src/main/java/oracle/kubernetes/operator/logging/LoggingFormatter.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.util.Map;
2020
import java.util.logging.Formatter;
2121
import java.util.logging.LogRecord;
22+
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
2223
import oracle.kubernetes.operator.work.Fiber;
24+
import oracle.kubernetes.operator.work.Packet;
2325

2426
/** Custom log formatter to format log messages in JSON format. */
2527
public class LoggingFormatter extends Formatter {
@@ -29,6 +31,7 @@ public class LoggingFormatter extends Formatter {
2931
private static final String TIMESTAMP = "timestamp";
3032
private static final String THREAD = "thread";
3133
private static final String FIBER = "fiber";
34+
private static final String DOMAIN_UID = "domainUID";
3235
private static final String SOURCE_CLASS = "class";
3336
private static final String SOURCE_METHOD = "method";
3437
private static final String TIME_IN_MILLIS = "timeInMillis";
@@ -109,6 +112,7 @@ public String format(LogRecord record) {
109112
map.put(TIMESTAMP, dateString);
110113
map.put(THREAD, thread);
111114
map.put(FIBER, fiber != null ? fiber.toString() : "");
115+
map.put(DOMAIN_UID, getDomainUID(fiber));
112116
map.put(LOG_LEVEL, level);
113117
map.put(SOURCE_CLASS, sourceClassName);
114118
map.put(SOURCE_METHOD, sourceMethodName);
@@ -138,4 +142,21 @@ public String format(LogRecord record) {
138142
}
139143
return json + "\n";
140144
}
145+
146+
/**
147+
* Get the domain UID currently being used by the step executing for the Fiber.
148+
*
149+
* @param fiber The current Fiber
150+
* @return the domain UID or empty string
151+
*/
152+
private String getDomainUID(Fiber fiber) {
153+
154+
Packet packet = fiber == null ? null : fiber.getPacket();
155+
if (packet != null) {
156+
DomainPresenceInfo info = packet.getSPI(DomainPresenceInfo.class);
157+
return info == null ? "" : info.getDomainUID();
158+
} else {
159+
return "";
160+
}
161+
}
141162
}

0 commit comments

Comments
 (0)