I'm logging the a
and b
values of a foldl
.
words = ["mate", "bro", "bruv"]
sum2 = List.foldl
(\a b ->
Debug.log(toString <| a)
Debug.log(toString <| b)
a
) "guv" words
It works as expected, but I can't understand the output:
"mate": <function>
"guv": "mate"
"bro": <function>
"mate": "bro"
"bruv": <function>
"bro": "bruv"
Why is it outputting a
as a <function>
, and what is it outputting b
as a:b
?
Debug logging is a troubleshooting process that gathers a large amount of information and system logs to help find problems. We recommend only enabling this for a short time, as the log files can become very large on the end device.
If you want to print the value of a variable at any given point, you might call Logger. debug . This combination of a configurable logging level and logging statements within your program allow you full control over how your application will log its activity.
DEBUG logging level is used to fetch information needed to diagnose, troubleshoot, or test an application. This ensures a smooth running application.
Debug logs are logs with an extended logging level. They can be helpful to support engineers when the application logs are insufficient to investigate an issue. Debug logs can be enabled for both Backup Manager and Recovery Console.
Debug.log
takes two arguments, a tag string, which can be anything, and then the value to be logged. Updating your code like this might work:
words = ["mate", "bro", "bruv"]
sum2 = List.foldl
(\a b
Debug.log "Value of a: " a
Debug.log "Value of b: " b
a
) "guv" words
Although, come to think of it, I think you need to do a bit of a trick for logging values that you don't want to return, like so:
words = ["mate", "bro", "bruv"]
sum2 = List.foldl
(\a b ->
let
_ = Debug.log "Value of a: " a
_ = Debug.log "Value of b: " b
in
a
) "guv" words
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With