ENH make logger print to stderr when running test commands
This commit is contained in:
parent
1142732dca
commit
24f0f034f0
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue