Custom logging function

Hi All,

I’m trying to write a custom function to log statements into canton log while exercising choices.

However this function will accept currentTimeStamp, contract/choice name and message text as parameters and will concatenate this values and save it into canton log file for debugging purposes

custom_logging_function : Time -> Text -> Text -> ()
custom_logging_function timeValue contractValue messageValue = debug "timeStamp : " <> show timeValue <> "contractName : " <> show contractValue <> "messageText : " <> show messageValue

But I’m getting an error “Couldn’t match expected type ‘()’ with actual type ‘m0 ()’”

What is wrong with this code, or any better approach that could be used.

Any input is appreciated. Thank you!

First, your code is equivalent to (debug "timeStamp :") <> (show timeValue) <> ..., which is probably not what you mean.

Second, debug returns a value that is not (). I suspect that you are putting your custom_logging_function calls under do, and therefore you actually want this value to be returned, not dropped on the floor.

Finally, it looks like you want to use debugRaw rather than debug. However, it might be nicer to define a data type with fields named after your strings here, add deriving (Show), and pass a value of that data type to debug, rather than manually appending a string together.

1 Like

Hi @Stephen

Yes, you are right this function is anticipated to be called under do block and creating a data type for concatenating values would be a cleaner approach.

Thank you for the input. :slight_smile: