summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-19 13:16:08 -0400
committerAndrew Cady <d@jerkface.net>2018-06-19 13:16:08 -0400
commit6fbb62f3828b8594be82676878f8402023a644ea (patch)
treed7e3dc460cfdaf15073ca2125268be88fa46570f
parent12b585d1f712540f70a26095a8c13df554161c47 (diff)
implement DPut using hslogger
-rw-r--r--dht-client.cabal1
-rw-r--r--src/DPut.hs23
2 files changed, 13 insertions, 11 deletions
diff --git a/dht-client.cabal b/dht-client.cabal
index 3a866e45..4d66af24 100644
--- a/dht-client.cabal
+++ b/dht-client.cabal
@@ -203,6 +203,7 @@ library
203 , hinotify < 0.3.10 203 , hinotify < 0.3.10
204 , reference 204 , reference
205 , avahi >= 0.2.0 205 , avahi >= 0.2.0
206 , hslogger
206 207
207 if impl(ghc < 8) 208 if impl(ghc < 8)
208 Build-depends: transformers 209 Build-depends: transformers
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