@@ -27,6 +27,7 @@ internal actual object LoggingContext {
2727
2828 for (index in fields.indices) {
2929 val field = fields[index]
30+ val keyForLoggingContext = field.getKeyForLoggingContext()
3031
3132 // Skip duplicate keys in the field array
3233 if (isDuplicateField(field, index, fields)) {
@@ -51,30 +52,30 @@ internal actual object LoggingContext {
5152 * here. The previous field will then be restored by [removeFields] after the context
5253 * exits.
5354 */
54- if (field.key != field. keyForLoggingContext) {
55+ if (field.key != keyForLoggingContext) {
5556 MDC .remove(field.key)
5657 }
5758 }
5859 }
5960
6061 /* *
61- * [JsonLogField] adds a suffix to [LogField. keyForLoggingContext] , i.e. it will be different
62- * from [LogField.key]. In this case, we want to check existing context field values for both
63- * [LogField.key] _and_ [LogField. keyForLoggingContext] .
62+ * [JsonLogField] adds a suffix to ` keyForLoggingContext` , i.e. it will be different from
63+ * [LogField.key]. In this case, we want to check existing context field values for both `key`
64+ * _and_ ` keyForLoggingContext` .
6465 */
65- if (field.key != field. keyForLoggingContext && existingValue == null ) {
66- existingValue = MDC .get(field. keyForLoggingContext)
66+ if (field.key != keyForLoggingContext && existingValue == null ) {
67+ existingValue = MDC .get(keyForLoggingContext)
6768 when (existingValue) {
6869 null -> {}
6970 field.value -> continue
7071 else -> {
7172 overwrittenFields =
72- overwrittenFields.set(index, field. keyForLoggingContext, existingValue, fields.size)
73+ overwrittenFields.set(index, keyForLoggingContext, existingValue, fields.size)
7374 }
7475 }
7576 }
7677
77- MDC .put(field. keyForLoggingContext, field.value)
78+ MDC .put(keyForLoggingContext, field.value)
7879 }
7980
8081 return overwrittenFields
@@ -92,6 +93,7 @@ internal actual object LoggingContext {
9293 ) {
9394 for (index in fields.indices) {
9495 val field = fields[index]
96+ val keyForLoggingContext = field.getKeyForLoggingContext()
9597
9698 // Skip duplicate keys, like we do in addFields
9799 if (isDuplicateField(field, index, fields)) {
@@ -106,12 +108,12 @@ internal actual object LoggingContext {
106108 * to call `MDC.remove` below (these may not always match for [JsonLogField] - see docstring
107109 * over `MDC.remove` in [addFields]).
108110 */
109- if (overwrittenKey == field. keyForLoggingContext) {
111+ if (overwrittenKey == keyForLoggingContext) {
110112 continue
111113 }
112114 }
113115
114- MDC .remove(field. keyForLoggingContext)
116+ MDC .remove(keyForLoggingContext)
115117 }
116118 }
117119
0 commit comments