summaryrefslogtreecommitdiff
path: root/src/DPut.hs
blob: 84f086b334c40ac371d2dd6e33b2f86d9e375d70 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)
import System.Log.Logger
import qualified Data.ByteString.Char8 as B
import qualified Data.Text as T
import qualified Data.Text.Encoding as T

-- | Debug Tags, add more as needed, but ensure XAnnounce is always first, XMisc last
data DebugTag = XAnnounce | XBitTorrent | XDHT | XLan | XMan | XNetCrypto | XOnion | XRoutes | XPing | XRefresh | XJabber | XMisc
    deriving (Eq,Ord,Show,Read,Enum,Bounded)

appName :: String
appName = "toxmpp"

(<.>) :: String -> String -> String
a <.> b = a ++ "." ++ b

dput :: DebugTag -> String -> IO ()
dput tag msg = debugM (appName <.> show tag) msg

dputB :: DebugTag -> B.ByteString -> IO ()
dputB tag msg = debugM (appName <.> show tag) (T.unpack . T.decodeUtf8 $ msg)

setTagLevel :: Priority -> DebugTag -> IO ()
setTagLevel level tag = updateGlobalLogger (appName <.> show tag) (setLevel level)

setQuiet :: DebugTag -> IO ()
setQuiet = setTagLevel WARNING

setVerbose :: DebugTag -> IO ()
setVerbose = setTagLevel DEBUG

getVerbose tag = do
    logger <- getLogger (appName <.> show tag)
    case getLevel logger of
        Just p | p <= DEBUG -> return True
        _ -> return False