Revision 426f0900 src/Ganeti/Logging.hs

b/src/Ganeti/Logging.hs
46 46
  , SyslogUsage(..)
47 47
  , syslogUsageToRaw
48 48
  , syslogUsageFromRaw
49
  , withErrorLogAt
49 50
  ) where
50 51

  
51 52
import Control.Monad
52
import Control.Monad.Error (Error(..))
53
import Control.Monad.Error (Error(..), MonadError(..), catchError)
53 54
import Control.Monad.Reader
54 55
import System.Log.Logger
55 56
import System.Log.Handler.Simple
......
173 174
-- | Log at emergency level.
174 175
logEmergency :: (MonadLog m) => String -> m ()
175 176
logEmergency = logAt EMERGENCY
177

  
178
-- * Logging in an error monad with rethrowing errors
179

  
180
-- | If an error occurs within a given computation, it annotated
181
-- with a given message and logged and the error is re-thrown.
182
withErrorLogAt :: (MonadLog m, MonadError e m, Show e)
183
               => Priority -> String -> m a -> m a
184
withErrorLogAt prio msg = flip catchError $ \e -> do
185
  logAt prio (msg ++ ": " ++ show e)
186
  throwError e

Also available in: Unified diff