on master help sign in
Make all logging functions ignore empty log messages
commit3b1db317c1f84cd7a67f5e22fc57371c77ec461b authorElliot Cameron <eacameron@gmail.com> dateFri 17 Jan 2020, 16:59 (7 years ago) parent841b483
1 file changed+9−7
lib/cliapp/src/Obelisk/CliApp/Logging.hs+9−7
lib/cliapp/src/Obelisk/CliApp/Logging.hs+9−7
@@ -178,14 +178,16 @@ withExitFailMessage msg f = f `catch` \(e :: ExitCode) -> do
178178
179179-- | Write log to stdout, with colors (unless `noColor`)
180180writeLog :: (MonadIO m, MonadMask m) => Bool -> Bool -> WithSeverity Text -> m ()
181−writeLog withNewLine noColor (WithSeverity severity s)
182− | noColor && severity <= Warning = liftIO $ putFn $ T.pack (show severity) <> ": " <> s
183− | not noColor && severity <= Error = TS.putStrWithSGR errorColors h withNewLine s
184− | not noColor && severity <= Warning = TS.putStrWithSGR warningColors h withNewLine s
185− | not noColor && severity >= Debug = TS.putStrWithSGR debugColors h withNewLine s
186− | otherwise = liftIO $ putFn s
181+writeLog withNewLine noColor (WithSeverity severity s) = if T.null s then pure () else write
187182 where
188− putFn = if withNewLine then (T.hPutStrLn h) else (T.hPutStr h)
183+ write
184+ | noColor && severity <= Warning = liftIO $ putFn $ T.pack (show severity) <> ": " <> s
185+ | not noColor && severity <= Error = TS.putStrWithSGR errorColors h withNewLine s
186+ | not noColor && severity <= Warning = TS.putStrWithSGR warningColors h withNewLine s
187+ | not noColor && severity >= Debug = TS.putStrWithSGR debugColors h withNewLine s
188+ | otherwise = liftIO $ putFn s
189+
190+ putFn = if withNewLine then T.hPutStrLn h else T.hPutStr h
189191 h = if severity <= Error then stderr else stdout
190192 errorColors = [SetColor Foreground Vivid Red]
191193 warningColors = [SetColor Foreground Vivid Yellow]