diff --git a/bin/xmobar.hs b/bin/xmobar.hs index 39205a8..b1a35e3 100644 --- a/bin/xmobar.hs +++ b/bin/xmobar.hs @@ -65,11 +65,10 @@ parseTest = (long "test" <> short 't' <> help "test dependencies without running") xio :: XOpts -> IO () -xio o = runXIO "xmobar.log" $ - case o of - XDeps -> printDeps - XTest -> withDBus_ evalConfig - XRun -> run +xio o = case o of + XDeps -> hRunXIO False stderr printDeps + XTest -> hRunXIO False stderr $ withDBus_ evalConfig + XRun -> runXIO "xmobar.log" run run :: XIO () run = do diff --git a/bin/xmonad.hs b/bin/xmonad.hs index b7f8b13..917de35 100644 --- a/bin/xmonad.hs +++ b/bin/xmonad.hs @@ -91,11 +91,10 @@ parseTest = (long "test" <> short 't' <> help "test dependencies without running") xio :: XOpts -> IO () -xio o = runXIO "xmonad.log" $ - case o of - XDeps -> printDeps - XTest -> undefined - XRun -> run +xio o = case o of + XDeps -> hRunXIO False stderr printDeps + XTest -> undefined + XRun -> runXIO "xmonad.log" run run :: XIO () run = do diff --git a/lib/Data/Internal/XIO.hs b/lib/Data/Internal/XIO.hs index 6813146..b516e6a 100644 --- a/lib/Data/Internal/XIO.hs +++ b/lib/Data/Internal/XIO.hs @@ -58,6 +58,7 @@ module Data.Internal.XIO -- testing , XIO , runXIO + , hRunXIO , evalFeature , executeSometimes , executeAlways @@ -133,8 +134,9 @@ import XMonad.Internal.Theme -- | Run feature evaluation(s) with the cache -- Currently there is no easy way to not use this (oh well) runXIO :: FilePath -> XIO a -> IO a -runXIO logfile x = withLogFile logfile $ runXIOInner x +runXIO logfile x = withLogFile logfile $ \h -> hRunXIO True h x +-- TODO use dhall to encode config file and log here to control the loglevel withLogFile :: MonadUnliftIO m => FilePath -> (Handle -> m a) -> m a withLogFile logfile f = do p <- ( logfile) . dataDir <$> liftIO getDirectories @@ -143,16 +145,20 @@ withLogFile logfile f = do liftIO $ putStrLn "could not open log file, falling back to stderr" f stderr -runXIOInner :: XIO a -> Handle -> IO a -runXIOInner x h = do +hRunXIO :: Bool -> Handle -> XIO a -> IO a +hRunXIO verbose h x = do hSetBuffering h LineBuffering - logOpts <- setLogVerboseFormat True . setLogUseTime True <$> logOptionsHandle h False + logOpts <- logOptionsHandle_ verbose h pc <- mkDefaultProcessContext withLogFunc logOpts $ \f -> do p <- getParams let s = XEnv f pc p runRIO s x +logOptionsHandle_ :: MonadUnliftIO m => Bool -> Handle -> m LogOptions +logOptionsHandle_ v h = + setLogVerboseFormat v . setLogUseTime v <$> logOptionsHandle h False + -- | Execute an Always immediately executeAlways :: Always (IO a) -> XIO a executeAlways = io <=< evalAlways diff --git a/lib/Xmobar/Plugins/Common.hs b/lib/Xmobar/Plugins/Common.hs index ee37da8..abefb83 100644 --- a/lib/Xmobar/Plugins/Common.hs +++ b/lib/Xmobar/Plugins/Common.hs @@ -12,7 +12,6 @@ module Xmobar.Plugins.Common , displayMaybe , displayMaybe' , xmobarFGColor - , LogConf (..) ) where @@ -88,10 +87,3 @@ withDBusClientConnection cb logfile f = withLogFunc logOpts $ \lf -> do env <- mkSimpleApp lf Nothing runRIO env $ displayMaybe' cb f =<< getDBusClient - -data LogConf = LogConf - { lcLevel :: !LogLevel - , lcVerbose :: !Bool - , lcPath :: FilePath - } - deriving (Show, Read)