From 43e165152767bc0f669a2ece45eb17fb4bf72db8 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 9 Nov 2020 20:06:13 +0100 Subject: [PATCH] GH-592 Logging improvements Resolves #592 --- .../catalog/SimpleFunctionRegistry.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java index 8980a88fe..bc11e4a4b 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistry.java @@ -133,6 +133,10 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect @Override public void register(FunctionRegistration registration) { + Assert.notNull(registration, "'registration' must not be null"); + if (logger.isDebugEnabled()) { + logger.debug("Registering function " + registration.getNames()); + } this.functionRegistrations.add(registration); } @@ -169,7 +173,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect if (function != null) { function.expectedOutputContentType = expectedOutputMimeTypes; } - else { + else if (logger.isDebugEnabled()) { logger.debug("Function '" + functionDefinition + "' is not found in cache"); } @@ -260,6 +264,9 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect this.wrappedFunctionDefinitions.put(composedFunction.functionDefinition, composedFunction); } } + if (logger.isDebugEnabled()) { + logger.debug("Composed function " + composedFunction); + } return composedFunction; } @@ -329,10 +336,16 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect } public void setSkipInputConversion(boolean skipInputConversion) { + if (logger.isDebugEnabled() && skipInputConversion) { + logger.debug("'skipInputConversion' was explicitely set to true. No input conversion will be attempted"); + } this.skipInputConversion = skipInputConversion; } public void setSkipOutputConversion(boolean skipOutputConversion) { + if (logger.isDebugEnabled() && skipOutputConversion) { + logger.debug("'skipOutputConversion' was explicitely set to true. No output conversion will be attempted"); + } this.skipOutputConversion = skipOutputConversion; } @@ -398,7 +411,9 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect */ @Override public Object apply(Object input) { - + if (logger.isDebugEnabled() && !(input instanceof Publisher)) { + logger.debug("Invoking function " + this); + } Object result = this.doApply(input); if (result != null && this.outputType != null) { @@ -795,9 +810,15 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect ? new OriginalMessageHolder(convertedInput, (Message) input) : convertedInput; } + if (convertedInput != null && logger.isDebugEnabled()) { + logger.debug("Converted Message: " + input + " to: " + convertedInput); + } } else { convertedInput = this.convertNonMessageInputIfNecessary(type, input); + if (convertedInput != null && logger.isDebugEnabled()) { + logger.debug("Converted input: " + input + " to: " + convertedInput); + } } // wrap in Message if necessary if (this.isWrapConvertedInputInMessage(convertedInput)) { @@ -828,7 +849,6 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect return output; } - Object convertedOutput = output; if (FunctionTypeUtils.isMultipleArgumentType(type)) { convertedOutput = this.convertMultipleOutputArgumentTypeIfNecesary(convertedOutput, type, contentType); @@ -944,7 +964,6 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect return message.getPayload(); } } - //if (message.getPayload().getClass().isAss) { Object convertedInput = message; type = this.extractActualValueTypeIfNecessary(type);