diff options
author | jim@bo <jim@bo> | 2018-06-20 22:40:37 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-20 22:43:47 -0400 |
commit | 825962518c6ad00279fc23e8e1dec746980e483f (patch) | |
tree | 68c135bdffd879835c48cce3d397e8edf99b53f4 /src/DPut.hs | |
parent | 09aa079fbab069f177e08b5239bf684d312eb00a (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.hs | 16 |
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) | |||
6 | import Data.Maybe | 6 | import Data.Maybe |
7 | import System.IO.Unsafe (unsafePerformIO) | 7 | import System.IO.Unsafe (unsafePerformIO) |
8 | import System.Log.Logger | 8 | import System.Log.Logger |
9 | import qualified Data.ByteString.Char8 as B | ||
10 | import qualified Data.Text as T | ||
11 | import qualified Data.Text.Encoding as T | ||
9 | 12 | ||
10 | data DebugTag = XAnnounce | XDHT | XOnion | XNetCrypto | XPing | XLan | XMisc | XWLog | 13 | -- | Debug Tags, add more as needed, but ensure XAnnounce is always first, XMisc last |
14 | data 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 | ||
13 | appName :: String | 17 | appName :: String |
@@ -19,6 +23,9 @@ a <.> b = a ++ "." ++ b | |||
19 | dput :: DebugTag -> String -> IO () | 23 | dput :: DebugTag -> String -> IO () |
20 | dput tag msg = debugM (appName <.> show tag) msg | 24 | dput tag msg = debugM (appName <.> show tag) msg |
21 | 25 | ||
26 | dputB :: DebugTag -> B.ByteString -> IO () | ||
27 | dputB tag msg = debugM (appName <.> show tag) (T.unpack . T.decodeUtf8 $ msg) | ||
28 | |||
22 | setTagLevel :: Priority -> DebugTag -> IO () | 29 | setTagLevel :: Priority -> DebugTag -> IO () |
23 | setTagLevel level tag = updateGlobalLogger (appName <.> show tag) (setLevel level) | 30 | setTagLevel level tag = updateGlobalLogger (appName <.> show tag) (setLevel level) |
24 | 31 | ||
@@ -27,3 +34,10 @@ setQuiet = setTagLevel WARNING | |||
27 | 34 | ||
28 | setVerbose :: DebugTag -> IO () | 35 | setVerbose :: DebugTag -> IO () |
29 | setVerbose = setTagLevel DEBUG | 36 | setVerbose = setTagLevel DEBUG |
37 | |||
38 | getVerbose tag = do | ||
39 | logger <- getLogger (appName <.> show tag) | ||
40 | case getLevel logger of | ||
41 | Just p | p <= DEBUG -> return True | ||
42 | _ -> return False | ||
43 | |||