Skip to content

Commit 8cfb6c7

Browse files
committed
Remove member from stateless logging formatter
1 parent 5089bf0 commit 8cfb6c7

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

common/src/main/java/oracle/kubernetes/common/logging/BaseLoggingFormatter.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.logging;
@@ -40,8 +40,6 @@ public abstract class BaseLoggingFormatter<T> extends Formatter {
4040

4141
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
4242

43-
protected T fiberObject = null;
44-
4543
@Override
4644
public String format(LogRecord logRecord) {
4745
String sourceClassName = "";
@@ -74,11 +72,11 @@ public String format(LogRecord logRecord) {
7472
final String dateString = DATE_FORMAT.format(OffsetDateTime.ofInstant(logRecord.getInstant(),
7573
ZoneId.systemDefault()));
7674
long thread = Thread.currentThread().getId();
77-
fiberObject = getCurrentFiberIfSet();
75+
T fiberObject = getCurrentFiberIfSet();
7876

7977
map.put(TIMESTAMP, dateString);
8078
map.put(THREAD, thread);
81-
Optional.ofNullable(getFiber()).ifPresent(f -> map.put(FIBER, f));
79+
map.put(FIBER, Optional.ofNullable(fiberObject).map(Object::toString).orElse(""));
8280
Optional.ofNullable(getNamespace(fiberObject)).ifPresent(namespace -> map.put(DOMAIN_NAMESPACE, namespace));
8381
Optional.ofNullable(getDomainUid(fiberObject)).ifPresent(uid -> map.put(DOMAIN_UID, uid));
8482
map.put(LOG_LEVEL, level);
@@ -114,9 +112,9 @@ public String format(LogRecord logRecord) {
114112

115113
protected abstract void serializeModelObjectsWithJSON(LogRecord logRecord);
116114

117-
protected abstract T getCurrentFiberIfSet();
118-
119-
protected abstract String getFiber();
115+
protected T getCurrentFiberIfSet() {
116+
return null;
117+
}
120118

121119
protected abstract String getNamespace(T fiber);
122120

common/src/main/java/oracle/kubernetes/common/logging/CommonLoggingFormatter.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.common.logging;
@@ -10,16 +10,6 @@
1010
/** Common log formatter to format log messages in JSON format. */
1111
public class CommonLoggingFormatter extends BaseLoggingFormatter<Object> {
1212

13-
@Override
14-
protected Object getCurrentFiberIfSet() {
15-
return null;
16-
}
17-
18-
@Override
19-
protected String getFiber() {
20-
return null;
21-
}
22-
2313
@Override
2414
protected String getDomainUid(Object fiber) {
2515
return null;

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.logging;
@@ -24,11 +24,6 @@ protected Fiber getCurrentFiberIfSet() {
2424
return Fiber.getCurrentIfSet();
2525
}
2626

27-
@Override
28-
protected String getFiber() {
29-
return fiberObject != null ? fiberObject.toString() : "";
30-
}
31-
3227
/**
3328
* Get the domain UID associated with the current log message.
3429
* Check the fiber that is currently being used to execute the step that initiates the log.

0 commit comments

Comments
 (0)