aboutsummaryrefslogtreecommitdiff
path: root/CabalHelper/Compiletime/Log.hs
blob: e4033f1c923a2fe43bd87c5c902b3ce5b89398af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module CabalHelper.Compiletime.Log where

import Control.Monad
import Control.Monad.IO.Class
import Control.Exception as E
import Data.String
import System.IO
import Prelude

import CabalHelper.Shared.Types

vLog :: MonadIO m => Options -> String -> m ()
vLog Options { verbose = True } msg =
    liftIO $ hPutStrLn stderr msg
vLog _ _ = return ()

logSomeError :: Options -> String -> IO (Maybe a) -> IO (Maybe a)
logSomeError opts label a = do
  a `E.catch` \se@(SomeException _) -> do
      vLog opts $ label ++ ": " ++ show se
      return Nothing