summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-05-29 03:37:28 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-05-29 03:37:28 +0000
commitbe48775177ac1d22f868b252b9517354f69a452d (patch)
treec3768414e88c61d013c53866f33bf46efa0aebec /src
parent1c65905502df013ab0076726aa919b91c14d7a4c (diff)
oops, left out new module in last commit
Diffstat (limited to 'src')
-rw-r--r--src/DPut.hs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/DPut.hs b/src/DPut.hs
new file mode 100644
index 00000000..abf926b5
--- /dev/null
+++ b/src/DPut.hs
@@ -0,0 +1,28 @@
1module DPut where
2
3import Control.Concurrent.STM
4import qualified Data.Map.Strict as Map
5import System.IO (stderr,hPutStrLn)
6import Data.Maybe
7import System.IO.Unsafe (unsafePerformIO)
8
9data DebugTag = XAnnounce | XDHT | XOnion | XNetCrypto | XMisc
10 deriving (Eq,Ord,Show,Read)
11
12{-# NOINLINE verbosityMap #-}
13verbosityMap :: TVar (Map.Map DebugTag Bool)
14verbosityMap = unsafePerformIO $ newTVarIO (Map.empty)
15
16dput :: DebugTag -> String -> IO ()
17dput tag msg
18 = do
19 mp <- atomically $ readTVar verbosityMap
20 if fromMaybe True (Map.lookup tag mp)
21 then System.IO.hPutStrLn stderr msg
22 else return ()
23
24setQuiet :: DebugTag -> IO ()
25setQuiet tag = atomically $ modifyTVar' (verbosityMap) (Map.insert tag False)
26
27setVerbose :: DebugTag -> IO ()
28setVerbose tag = atomically $ modifyTVar' (verbosityMap) (Map.insert tag True)