summaryrefslogtreecommitdiff
path: root/src/DPut.hs
blob: 11bcc2d081b01b511d6410b735fcd208eaee0f5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module DPut where

import Control.Concurrent.STM
import qualified Data.Map.Strict as Map
import System.IO (stderr,hPutStrLn)
import Data.Maybe
import System.IO.Unsafe (unsafePerformIO)

data DebugTag = XAnnounce | XDHT | XOnion | XNetCrypto | XPing | XMisc
    deriving (Eq,Ord,Show,Read)

{-# NOINLINE verbosityMap #-}
verbosityMap :: TVar (Map.Map DebugTag Bool)
verbosityMap = unsafePerformIO $ newTVarIO (Map.empty)

dput :: DebugTag -> String -> IO ()
dput tag msg
    = do
       mp <- atomically $ readTVar verbosityMap
       if fromMaybe True (Map.lookup tag mp)
        then System.IO.hPutStrLn stderr msg
        else return ()

setQuiet :: DebugTag -> IO ()
setQuiet tag = atomically $ modifyTVar' (verbosityMap) (Map.insert tag False)

setVerbose :: DebugTag -> IO ()
setVerbose tag = atomically $ modifyTVar' (verbosityMap) (Map.insert tag True)