@@ -16,11 +16,11 @@ import Prelude ()
1616import Distribution.Simple.Utils
1717import Distribution.Utils.Progress
1818import Distribution.Verbosity
19- import System.IO (hPutStrLn )
19+ import System.IO (hFlush , hPutStr , hPutStrLn )
2020import Text.PrettyPrint
2121
2222type CtxMsg = Doc
23- type LogMsg = Doc
23+ data LogMsg = WarnMsg Doc | InfoMsg Doc
2424type ErrMsg = Doc
2525
2626data LogEnv = LogEnv
@@ -55,10 +55,19 @@ runLogProgress verbosity (LogProgress m) =
5555 , le_context = []
5656 }
5757 step_fn :: LogMsg -> IO a -> IO a
58- step_fn doc go = do
58+ step_fn (WarnMsg doc) go = do
59+ -- Log the warning to the stderr handle, but flush the stdout handle first,
60+ -- to prevent interleaving (see Distribution.Simple.Utils.warnMessage).
61+ let h = verbosityErrorHandle verbosity
62+ flags = verbosityFlags verbosity
63+ hFlush (verbosityChosenOutputHandle verbosity)
64+ hPutStr h $ withOutputMarker flags (render doc ++ " \n " )
65+ go
66+ step_fn (InfoMsg doc) go = do
67+ -- Don't mark 'infoProgress' messages (mostly Backpack internals)
5968 hPutStrLn (verbosityChosenOutputHandle verbosity) (render doc)
6069 go
61- fail_fn :: Doc -> IO a
70+ fail_fn :: ErrMsg -> IO a
6271 fail_fn doc = do
6372 dieNoWrap verbosity (render doc)
6473
@@ -67,13 +76,15 @@ warnProgress :: Doc -> LogProgress ()
6776warnProgress s = LogProgress $ \ env ->
6877 when (verbosityLevel (le_verbosity env) >= Normal ) $
6978 stepProgress $
70- hang (text " Warning:" ) 4 (formatMsg (le_context env) s)
79+ WarnMsg $
80+ hang (text " Warning:" ) 4 (formatMsg (le_context env) s)
7181
7282-- | Output an informational trace message in 'LogProgress'.
7383infoProgress :: Doc -> LogProgress ()
7484infoProgress s = LogProgress $ \ env ->
7585 when (verbosityLevel (le_verbosity env) >= Verbose ) $
76- stepProgress s
86+ stepProgress $
87+ InfoMsg s
7788
7889-- | Fail the computation with an error message.
7990dieProgress :: Doc -> LogProgress a
0 commit comments