From a9f774c0a46584587a498d5690464c71a2f0f638 Mon Sep 17 00:00:00 2001 From: joe Date: Sun, 8 Jan 2017 16:36:56 -0500 Subject: Logging filter interface for dht. --- src/Network/BitTorrent/DHT.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/Network/BitTorrent') diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs index 3867d182..7ca8fc8b 100644 --- a/src/Network/BitTorrent/DHT.hs +++ b/src/Network/BitTorrent/DHT.hs @@ -21,6 +21,7 @@ module Network.BitTorrent.DHT ( -- * Distributed Hash Table DHT , Options (..) + , fullLogging , dht -- * Bootstrapping @@ -82,14 +83,19 @@ class MonadDHT m where instance MonadDHT (DHT IPv4) where liftDHT = id +-- | Convenience method. Pass this to 'dht' to enable full logging. +fullLogging :: LogSource -> LogLevel -> Bool +fullLogging _ _ = True + -- | Run DHT on specified port. dht :: Address ip => Options -- ^ normally you need to use 'Data.Default.def'; -> NodeAddr ip -- ^ address to bind this node; + -> (LogSource -> LogLevel -> Bool) -- ^ use 'fullLogging' as a noisy default -> DHT ip a -- ^ actions to run: 'bootstrap', 'lookup', etc; -> IO a -- ^ result. -dht opts addr action = do - runStderrLoggingT $ LoggingT $ \ logger -> do +dht opts addr logfilter action = do + runStderrLoggingT $ filterLogger logfilter $ LoggingT $ \ logger -> do bracket (newNode defaultHandlers opts addr logger Nothing) closeNode $ \ node -> runDHT node action {-# INLINE dht #-} -- cgit v1.2.3