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") (long "test" <> short 't' <> help "test dependencies without running")
xio :: XOpts -> IO () xio :: XOpts -> IO ()
xio o = runXIO $ xio o = runXIO "xmobar.log" $
case o of case o of
XDeps -> printDeps XDeps -> printDeps
XTest -> withDBus_ evalConfig XTest -> withDBus_ evalConfig

View File

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

View File

@ -118,7 +118,7 @@ import qualified RIO.Text as T
import System.Posix.Files import System.Posix.Files
import System.Process.Typed (nullStream) import System.Process.Typed (nullStream)
import UnliftIO.Environment import UnliftIO.Environment
import XMonad.Core (X, io) import XMonad.Core (X, dataDir, getDirectories, io)
import XMonad.Internal.IO import XMonad.Internal.IO
import XMonad.Internal.Shell hiding (proc, runProcess) import XMonad.Internal.Shell hiding (proc, runProcess)
import XMonad.Internal.Theme import XMonad.Internal.Theme
@ -131,9 +131,18 @@ import XMonad.Internal.Theme
-- | Run feature evaluation(s) with the cache -- | Run feature evaluation(s) with the cache
-- Currently there is no easy way to not use this (oh well) -- Currently there is no easy way to not use this (oh well)
runXIO :: XIO a -> IO a runXIO :: FilePath -> XIO a -> IO a
runXIO x = do runXIO logfile x = do
logOpts <- setLogVerboseFormat True . setLogUseTime True <$> logOptionsHandle stderr False -- 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 pc <- mkDefaultProcessContext
withLogFunc logOpts $ \f -> do withLogFunc logOpts $ \f -> do
p <- getParams p <- getParams