ENH use log file instead of stderr

This commit is contained in:
Nathan Dwarshuis 2023-01-03 23:10:09 -05:00
parent a61b17502d
commit 6c3d8c3eaf
3 changed files with 15 additions and 6 deletions

View File

@ -65,7 +65,7 @@ parseTest =
(long "test" <> short 't' <> help "test dependencies without running")
xio :: XOpts -> IO ()
xio o = runXIO $
xio o = runXIO "xmobar.log" $
case o of
XDeps -> printDeps
XTest -> withDBus_ evalConfig

View File

@ -91,7 +91,7 @@ parseTest =
(long "test" <> short 't' <> help "test dependencies without running")
xio :: XOpts -> IO ()
xio o = runXIO $
xio o = runXIO "xmonad.log" $
case o of
XDeps -> printDeps
XTest -> undefined

View File

@ -118,7 +118,7 @@ import qualified RIO.Text as T
import System.Posix.Files
import System.Process.Typed (nullStream)
import UnliftIO.Environment
import XMonad.Core (X, io)
import XMonad.Core (X, dataDir, getDirectories, io)
import XMonad.Internal.IO
import XMonad.Internal.Shell hiding (proc, runProcess)
import XMonad.Internal.Theme
@ -131,9 +131,18 @@ import XMonad.Internal.Theme
-- | Run feature evaluation(s) with the cache
-- Currently there is no easy way to not use this (oh well)
runXIO :: XIO a -> IO a
runXIO x = do
logOpts <- setLogVerboseFormat True . setLogUseTime True <$> logOptionsHandle stderr False
runXIO :: FilePath -> XIO a -> IO a
runXIO logfile x = do
-- TODO this directory will not exist on a fresh system
p <- (</> logfile) . dataDir <$> getDirectories
catchIO (withFile p AppendMode $ runXIOInner x) $ \e -> do
print e
putStrLn "could not open log file, falling back to stderr"
runXIOInner x stderr
runXIOInner :: XIO a -> Handle -> IO a
runXIOInner x h = do
logOpts <- setLogVerboseFormat True . setLogUseTime True <$> logOptionsHandle h False
pc <- mkDefaultProcessContext
withLogFunc logOpts $ \f -> do
p <- getParams