switch from hslogger to purpose-built Utility.Debug

This uses a DebugSelector, rather than debug levels, which will allow
for a later option like --debug-from=Process to only
see debuging about running processes.

The module name that contains the thing being debugged is used as the
DebugSelector (in most cases; does not need to be a hard and fast rule).
Debug calls were changed to add that. hslogger did not display
that first parameter to debugM, but the DebugSelector does get
displayed.

Also fastDebug will allow doing debugging in places that are used in
tight loops, with the DebugSelector coming from the Annex Reader
essentially for free. Not done yet.
This commit is contained in:
Joey Hess 2021-04-05 13:40:31 -04:00
parent 19c672e710
commit aaba83795b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
26 changed files with 194 additions and 105 deletions

View file

@ -5,7 +5,7 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
{-# LANGUAGE RankNTypes, FlexibleContexts, CPP #-}
{-# LANGUAGE RankNTypes, FlexibleContexts, OverloadedStrings, CPP #-}
module P2P.IO
( RunProto
@ -35,6 +35,7 @@ import Utility.SimpleProtocol
import Utility.Metered
import Utility.Tor
import Utility.FileMode
import Utility.Debug
import Types.UUID
import Annex.ChangedRefs
import qualified Utility.RawFilePath as R
@ -48,7 +49,6 @@ import Control.Concurrent.Async
import Control.Concurrent.STM
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import System.Log.Logger (debugM)
import qualified Network.Socket as S
-- Type of interpreters of the Proto free monad.
@ -235,7 +235,7 @@ runNet runst conn runner f = case f of
debugMessage :: P2PConnection -> String -> Message -> IO ()
debugMessage conn prefix m = do
tid <- myThreadId
debugM "p2p" $ concat $ catMaybes $
debug "P2P.IO" $ concat $ catMaybes $
[ (\ident -> "[" ++ ident ++ "] ") <$> mident
, Just $ "[" ++ show tid ++ "] "
, Just $ prefix ++ " " ++ unwords (formatMessage safem)