Skip to content

Instantly share code, notes, and snippets.

@princejwesley
Last active May 27, 2016 02:23
Show Gist options
  • Save princejwesley/acca778c9221e2bdc5d2121d4a489f9b to your computer and use it in GitHub Desktop.
Save princejwesley/acca778c9221e2bdc5d2121d4a489f9b to your computer and use it in GitHub Desktop.
[elm] Toggle on/off Debug.log
-- Toggle Debug.log
-- For non production use only
import Debug exposing(log)
-- (1) with |>
1 + 1 |> log "Addition" -- prints "Addition: 2" and returns 2
-- turn off logging
1 + 1 -- |> log "Addition"
-- (2) with flip
flog = flip log
(1 + 1) `flog` "Addition" -- prints "Addition: 2" and returns 2
-- turn off logging
(1 + 1) -- `flog` "Addition"
-- (3) with xlog
xlog _ l = l
1 + (log "num" 1) -- prints "num: 1" and returns 2
-- turn off logging
1 + (xlog "num" 1) -- prints nothing and returns 2
-- (4) without exposing log
-- turn off/on all logs in a file
log = Debug.log
-- log _ l = l
1 + (log "num" 1) -- prints "num: 1" and returns 2
-- turn off logging
-- log = Debug.log
log _ l = l
1 + (log "num" 1) -- prints nothing and returns 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment