summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)