summaryrefslogtreecommitdiff
path: root/src/DPut.hs
diff options
context:
space:
mode:
authorjim@bo <jim@bo>2018-06-20 22:40:37 -0400
committerjim@bo <jim@bo>2018-06-20 22:43:47 -0400
commit825962518c6ad00279fc23e8e1dec746980e483f (patch)
tree68c135bdffd879835c48cce3d397e8edf99b53f4 /src/DPut.hs
parent09aa079fbab069f177e08b5239bf684d312eb00a (diff)
More DPut stuff
* verbose/quiet without args shows report * verbose all - sets all tags verbose * quiet all - sets all tags quiet * XMisc defaults to verbose, everything else quiet * new XMan tag for ToxManager related stuff * s/hputStrLn stderr/dput XMisc/ in daemon code
Diffstat (limited to 'src/DPut.hs')
-rw-r--r--src/DPut.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/DPut.hs b/src/DPut.hs
index b305a581..ff828112 100644
--- a/src/DPut.hs
+++ b/src/DPut.hs
@@ -6,8 +6,12 @@ import System.IO (stderr,hPutStrLn)
6import Data.Maybe 6import Data.Maybe
7import System.IO.Unsafe (unsafePerformIO) 7import System.IO.Unsafe (unsafePerformIO)
8import System.Log.Logger 8import System.Log.Logger
9import qualified Data.ByteString.Char8 as B
10import qualified Data.Text as T
11import qualified Data.Text.Encoding as T
9 12
10data DebugTag = XAnnounce | XDHT | XOnion | XNetCrypto | XPing | XLan | XMisc | XWLog 13-- | Debug Tags, add more as needed, but ensure XAnnounce is always first, XMisc last
14data DebugTag = XAnnounce | XBitTorrent | XDHT | XLan | XMan | XNetCrypto | XOnion | XPing | XRefresh | XWLog | XMisc
11 deriving (Eq,Ord,Show,Read,Enum,Bounded) 15 deriving (Eq,Ord,Show,Read,Enum,Bounded)
12 16
13appName :: String 17appName :: String
@@ -19,6 +23,9 @@ a <.> b = a ++ "." ++ b
19dput :: DebugTag -> String -> IO () 23dput :: DebugTag -> String -> IO ()
20dput tag msg = debugM (appName <.> show tag) msg 24dput tag msg = debugM (appName <.> show tag) msg
21 25
26dputB :: DebugTag -> B.ByteString -> IO ()
27dputB tag msg = debugM (appName <.> show tag) (T.unpack . T.decodeUtf8 $ msg)
28
22setTagLevel :: Priority -> DebugTag -> IO () 29setTagLevel :: Priority -> DebugTag -> IO ()
23setTagLevel level tag = updateGlobalLogger (appName <.> show tag) (setLevel level) 30setTagLevel level tag = updateGlobalLogger (appName <.> show tag) (setLevel level)
24 31
@@ -27,3 +34,10 @@ setQuiet = setTagLevel WARNING
27 34
28setVerbose :: DebugTag -> IO () 35setVerbose :: DebugTag -> IO ()
29setVerbose = setTagLevel DEBUG 36setVerbose = setTagLevel DEBUG
37
38getVerbose tag = do
39 logger <- getLogger (appName <.> show tag)
40 case getLevel logger of
41 Just p | p <= DEBUG -> return True
42 _ -> return False
43