From f711b91f176ba22820d58a204832121c7fbf232f Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 1 May 2020 09:41:40 +0200 Subject: Flameshot.Internal: add logger callbacks --- src/Flameshot/Internal.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Flameshot/Internal.hs b/src/Flameshot/Internal.hs index b01b145..fc561fe 100644 --- a/src/Flameshot/Internal.hs +++ b/src/Flameshot/Internal.hs @@ -21,6 +21,7 @@ import DBus.Socket import Data.Text (Text) import qualified Data.Text.Extended as T import qualified Flameshot.Internal.Process as P +import System.Exit blessBusName :: BusName -> Blessings Text @@ -111,3 +112,28 @@ showUnprintable = copyToClipboard :: String -> ByteString -> IO () copyToClipboard mimetype = P.writeDaemon "xclip" ["-selection", "clipboard", "-t", mimetype, "-i"] + +logger :: (Blessings Text -> IO ()) -> Text -> P.Callbacks +logger putLog name = + P.Callbacks + { P.onOutLine = \pid s -> + putLog' pid $ "stdout: " <> Plain s + + , P.onErrLine = \pid s -> + putLog' pid $ "stderr: " <> red (Plain s) + + , P.onError = \pid err -> + putLog' pid $ "error: " <> blessShow err + + , P.onExit = \pid status -> + case status of + ExitSuccess -> + putLog' pid $ "exited" + ExitFailure code -> + putLog' pid $ "exited with code " <> red (blessShow code) + + , P.onStart = \pid -> + putLog' pid "started" + } + where + putLog' pid s = putLog $ Plain name <> "[" <> blessShow pid <> "] " <> s -- cgit v1.2.3