Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elm: How does Debug.log work?

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 ?

like image 883
Rich Avatar asked Apr 10 '17 10:04

Rich


People also ask

What does debug log do?

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.

When would you use a debug logger?

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.

Is debug log important?

DEBUG logging level is used to fetch information needed to diagnose, troubleshoot, or test an application. This ensures a smooth running application.

What is extra debug logging?

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.


1 Answers

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
like image 77
ahstro Avatar answered Sep 25 '22 01:09

ahstro