Custom logging function
- prajwalhegde3OP
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 messageValueBut 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!
- Stephen 1
First, your code is equivalent to
(debug "timeStamp :") <> (show timeValue) <> ..., which is probably not what you mean.Second,
debugreturns a value that is not(). I suspect that you are putting yourcustom_logging_functioncalls underdo, and therefore you actually want this value to be returned, not dropped on the floor.Finally, it looks like you want to use
debugRawrather thandebug. However, it might be nicer to define adatatype with fields named after your strings here, addderiving (Show), and pass a value of that data type todebug, rather than manually appending a string together. - prajwalhegde3
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.
