Class LogUtil
- java.lang.Object
-
- org.eclipse.ditto.services.utils.akka.LogUtil
-
public final class LogUtil extends Object
Utilities for logging.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLogUtil.MdcFieldRepresents an MDC field that can be added to the MDC of a logger.
-
Field Summary
Fields Modifier and Type Field Description static StringX_CORRELATION_IDName of the Header for the global Ditto correlation ID.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidenhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, CharSequence correlationId, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry for the passedcorrelationId(if present).static voidenhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, Optional<String> correlationId, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry for the passedcorrelationId(if present).static voidenhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, org.eclipse.ditto.model.base.headers.DittoHeaders dittoHeaders, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry by extracting acorrelationIdof the passeddittoHeaders(if present).static voidenhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, org.eclipse.ditto.model.base.headers.WithDittoHeaders<?> withDittoHeaders, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry by extracting acorrelationIdof the passedwithDittoHeaders(if present).static voidenhanceLogWithCorrelationId(CharSequence correlationId)Enhances the default slf4jMDCwith acorrelationId.static voidenhanceLogWithCorrelationId(Optional<String> correlationId)Enhances the default slf4jMDCwith acorrelationId.static voidenhanceLogWithCorrelationId(org.eclipse.ditto.model.base.headers.DittoHeaders dittoHeaders)Enhances the default slf4jMDCwith acorrelationIdof the passeddittoHeaders(if present).static voidenhanceLogWithCorrelationId(org.eclipse.ditto.model.base.headers.WithDittoHeaders<?> withDittoHeaders)Enhances the default slf4jMDCwith acorrelationIdof the passedwithDittoHeaders(if present).static voidenhanceLogWithCorrelationIdOrRandom(org.eclipse.ditto.model.base.headers.DittoHeaders dittoHeaders)Enhances the default slf4jMDCwith acorrelationIdof the passeddittoHeaders(if present), else a random correlation ID.static voidenhanceLogWithCorrelationIdOrRandom(org.eclipse.ditto.model.base.headers.WithDittoHeaders<?> withDittoHeaders)Enhances the default slf4jMDCwith acorrelationIdof the passedwithDittoHeaders(if present), else a random correlation ID.static voidenhanceLogWithCustomField(akka.event.DiagnosticLoggingAdapter loggingAdapter, String fieldName, CharSequence fieldValue, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry for the passedfieldNamewith the passedfieldValue(if present).static voidenhanceLogWithCustomField(LogUtil.MdcField mdcField)Enhances the defaultMDCwith a map entry for the passedmdcFields.static Optional<String>getCorrelationId()Gets thecorrelationIdfrom the default slf4jMDC.static StringgetCorrelationId(Supplier<String> defaultCorrelationIdSupplier)Gets thecorrelationIdfrom the default slf4jMDC.static LogUtil.MdcFieldnewMdcField(String name, String value)Creates a new MDC field.static akka.event.DiagnosticLoggingAdapterobtain(akka.actor.Actor logSource)Obtain LoggingAdapter with MDC support for the given actor.static voidremoveCorrelationId()Removes thecorrelationIdfrom the default slf4jMDC.static voidremoveCustomField(akka.event.DiagnosticLoggingAdapter loggingAdapter, String fieldName)Removes thefieldNamefrom the default slf4jMDC.
-
-
-
Field Detail
-
X_CORRELATION_ID
public static final String X_CORRELATION_ID
Name of the Header for the global Ditto correlation ID.- See Also:
- Constant Field Values
-
-
Method Detail
-
obtain
public static akka.event.DiagnosticLoggingAdapter obtain(akka.actor.Actor logSource)
Obtain LoggingAdapter with MDC support for the given actor.- Parameters:
logSource- the Actor used as logSource- Returns:
- the created DiagnosticLoggingAdapter.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, org.eclipse.ditto.model.base.headers.WithDittoHeaders<?> withDittoHeaders, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry by extracting acorrelationIdof the passedwithDittoHeaders(if present).- Parameters:
loggingAdapter- the DiagnosticLoggingAdapter to set the "MDC" on.withDittoHeaders- where to extract a possible correlation ID from.additionalMdcFields- additional fields to add to the MDC.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, org.eclipse.ditto.model.base.headers.DittoHeaders dittoHeaders, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry by extracting acorrelationIdof the passeddittoHeaders(if present).- Parameters:
loggingAdapter- the DiagnosticLoggingAdapter to set the "MDC" on.dittoHeaders- where to extract a possible correlation ID from.additionalMdcFields- additional fields to add to the MDC.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, Optional<String> correlationId, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry for the passedcorrelationId(if present).- Parameters:
loggingAdapter- the DiagnosticLoggingAdapter to set the "MDC" on.correlationId- the optional correlation ID to set.additionalMdcFields- additional fields to add to the MDC.
-
enhanceLogWithCustomField
public static void enhanceLogWithCustomField(LogUtil.MdcField mdcField)
Enhances the defaultMDCwith a map entry for the passedmdcFields.- Parameters:
mdcField- the field to add to the MDC.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(akka.event.DiagnosticLoggingAdapter loggingAdapter, CharSequence correlationId, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry for the passedcorrelationId(if present).- Parameters:
loggingAdapter- the DiagnosticLoggingAdapter to set the "MDC" on.correlationId- the optional correlation ID to set.additionalMdcFields- additional fields to add to the MDC.
-
enhanceLogWithCustomField
public static void enhanceLogWithCustomField(akka.event.DiagnosticLoggingAdapter loggingAdapter, String fieldName, @Nullable CharSequence fieldValue, LogUtil.MdcField... additionalMdcFields)Enhances the passedDiagnosticLoggingAdapterwith an "MDC" map entry for the passedfieldNamewith the passedfieldValue(if present).- Parameters:
loggingAdapter- the DiagnosticLoggingAdapter to set the "MDC" on.fieldName- the field value to set in MDC.fieldValue- the optional value to set.additionalMdcFields- additional fields to add to the MDC.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(org.eclipse.ditto.model.base.headers.WithDittoHeaders<?> withDittoHeaders)
Enhances the default slf4jMDCwith acorrelationIdof the passedwithDittoHeaders(if present).- Parameters:
withDittoHeaders- where to extract a possible correlation ID from.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(org.eclipse.ditto.model.base.headers.DittoHeaders dittoHeaders)
Enhances the default slf4jMDCwith acorrelationIdof the passeddittoHeaders(if present).- Parameters:
dittoHeaders- where to extract a possible correlation ID from.
-
enhanceLogWithCorrelationIdOrRandom
public static void enhanceLogWithCorrelationIdOrRandom(org.eclipse.ditto.model.base.headers.WithDittoHeaders<?> withDittoHeaders)
Enhances the default slf4jMDCwith acorrelationIdof the passedwithDittoHeaders(if present), else a random correlation ID.- Parameters:
withDittoHeaders- where to extract a possible correlation ID from.
-
enhanceLogWithCorrelationIdOrRandom
public static void enhanceLogWithCorrelationIdOrRandom(org.eclipse.ditto.model.base.headers.DittoHeaders dittoHeaders)
Enhances the default slf4jMDCwith acorrelationIdof the passeddittoHeaders(if present), else a random correlation ID.- Parameters:
dittoHeaders- where to extract a possible correlation ID from.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(Optional<String> correlationId)
Enhances the default slf4jMDCwith acorrelationId.- Parameters:
correlationId- the optional correlation ID to set.
-
enhanceLogWithCorrelationId
public static void enhanceLogWithCorrelationId(@Nullable CharSequence correlationId)Enhances the default slf4jMDCwith acorrelationId.- Parameters:
correlationId- the optional correlation ID to set.
-
getCorrelationId
public static Optional<String> getCorrelationId()
Gets thecorrelationIdfrom the default slf4jMDC.- Returns:
- the
correlationIdfromMDCor an emptyOptionalif it didn't exist.
-
getCorrelationId
public static String getCorrelationId(Supplier<String> defaultCorrelationIdSupplier)
Gets thecorrelationIdfrom the default slf4jMDC.- Parameters:
defaultCorrelationIdSupplier- supplies a default correlation ID if none could be found insideMDC.- Returns:
- The
correlationIdfromMDCor fromdefaultCorrelationIdSupplierif it didn't exist.
-
removeCorrelationId
public static void removeCorrelationId()
Removes thecorrelationIdfrom the default slf4jMDC.
-
removeCustomField
public static void removeCustomField(akka.event.DiagnosticLoggingAdapter loggingAdapter, String fieldName)Removes thefieldNamefrom the default slf4jMDC.- Parameters:
loggingAdapter- the DiagnosticLoggingAdapter to remove the MDC field from.fieldName- the field to remove.
-
newMdcField
public static LogUtil.MdcField newMdcField(String name, @Nullable String value)
Creates a new MDC field.- Parameters:
name- the name of the field.value- the value of the field.- Returns:
- the MDC field for name and value.
- Throws:
NullPointerException- ifnameis null.
-
-