summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DPut.hs23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/DPut.hs b/src/DPut.hs
index dc699e76..3cb31160 100644
--- a/src/DPut.hs
+++ b/src/DPut.hs
@@ -5,24 +5,25 @@ import qualified Data.Map.Strict as Map
5import System.IO (stderr,hPutStrLn) 5import System.IO (stderr,hPutStrLn)
6import Data.Maybe 6import Data.Maybe
7import System.IO.Unsafe (unsafePerformIO) 7import System.IO.Unsafe (unsafePerformIO)
8import System.Log.Logger
8 9
9data DebugTag = XAnnounce | XDHT | XOnion | XNetCrypto | XPing | XLan | XMisc 10data DebugTag = XAnnounce | XDHT | XOnion | XNetCrypto | XPing | XLan | XMisc
10 deriving (Eq,Ord,Show,Read,Enum,Bounded) 11 deriving (Eq,Ord,Show,Read,Enum,Bounded)
11 12
12{-# NOINLINE verbosityMap #-} 13appName :: String
13verbosityMap :: TVar (Map.Map DebugTag Bool) 14appName = "toxmpp"
14verbosityMap = unsafePerformIO $ newTVarIO (Map.empty) 15
16(<.>) :: String -> String -> String
17a <.> b = a ++ "." ++ b
15 18
16dput :: DebugTag -> String -> IO () 19dput :: DebugTag -> String -> IO ()
17dput tag msg 20dput tag msg = debugM (appName <.> show tag) msg
18 = do 21
19 mp <- atomically $ readTVar verbosityMap 22setTagLevel :: Priority -> DebugTag -> IO ()
20 if fromMaybe True (Map.lookup tag mp) 23setTagLevel level tag = updateGlobalLogger (appName <.> show tag) (setLevel level)
21 then System.IO.hPutStrLn stderr msg
22 else return ()
23 24
24setQuiet :: DebugTag -> IO () 25setQuiet :: DebugTag -> IO ()
25setQuiet tag = atomically $ modifyTVar' (verbosityMap) (Map.insert tag False) 26setQuiet = setTagLevel WARNING
26 27
27setVerbose :: DebugTag -> IO () 28setVerbose :: DebugTag -> IO ()
28setVerbose tag = atomically $ modifyTVar' (verbosityMap) (Map.insert tag True) 29setVerbose = setTagLevel DEBUG