Skip to content

Commit

Permalink
trace-dispatcher: better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jutaro committed Dec 17, 2021
1 parent 68f6bbe commit 7165997
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions trace-dispatcher/src/Cardano/Logging/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Cardano.Logging.Configuration
, getBackends
) where

import Control.Exception (throwIO)
import Control.Exception (throwIO, SomeException, catch)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.IO.Unlift (MonadUnliftIO)
import qualified Control.Tracer as T
Expand Down Expand Up @@ -53,17 +53,27 @@ defaultConfig = emptyTraceConfig {
}

-- | Call this function at initialisation, and later for reconfiguration
configureTracers :: Monad m => TraceConfig -> Documented a -> [Trace m a]-> m ()
configureTracers config (Documented documented) tracers = do
mapM_ (configureTrace Reset) tracers
mapM_ (configureAllTrace (Config config)) tracers
mapM_ (configureTrace Optimize) tracers
where
configureTracers :: forall a.
TraceConfig
-> Documented a
-> [Trace IO a]
-> IO ()
configureTracers config (Documented documented) tracers =
catch
(do
mapM_ (configureTrace Reset) tracers
mapM_ (configureAllTrace (Config config)) tracers
mapM_ (configureTrace Optimize) tracers)
(\ (ex :: SomeException) -> print (show ex ++ " " ++ show (head documented)))
where
configureTrace control (Trace tr) =
T.traceWith tr (emptyLoggingContext, Just control, dmPrototype (head documented))
configureAllTrace control (Trace tr) =
mapM
((\ m -> T.traceWith tr (emptyLoggingContext, Just control, m)) . dmPrototype)
(\d ->
(catch
(((\ m -> T.traceWith tr (emptyLoggingContext, Just control, m)) . dmPrototype) d)
(\ (ex :: SomeException) -> print (show ex ++ " " ++ show d))))
documented

-- | Take a selector function called 'extract'.
Expand Down

0 comments on commit 7165997

Please sign in to comment.