aboutsummaryrefslogtreecommitdiff
path: root/src/Internal/Logger.hs
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2022-03-21 10:15:03 -0600
committerJosh Rahm <rahm@google.com>2022-03-21 10:15:03 -0600
commitcfb489be45b8222c4984b344ee4e1f2e760dd3b7 (patch)
tree1a1d8c4f6d804ab6560157603785d3aee00ae213 /src/Internal/Logger.hs
parente2b8c1c7e934009e26ad640d75c689211f51cc1b (diff)
parenta87cbc7357566b26c7dca7538d4b03da5f8b999a (diff)
downloadrde-cfb489be45b8222c4984b344ee4e1f2e760dd3b7.tar.gz
rde-cfb489be45b8222c4984b344ee4e1f2e760dd3b7.tar.bz2
rde-cfb489be45b8222c4984b344ee4e1f2e760dd3b7.zip
Merge branch 'v017' of git.josher.dev:rde into v017
Diffstat (limited to 'src/Internal/Logger.hs')
-rw-r--r--src/Internal/Logger.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Internal/Logger.hs b/src/Internal/Logger.hs
new file mode 100644
index 0000000..f1960fb
--- /dev/null
+++ b/src/Internal/Logger.hs
@@ -0,0 +1,36 @@
+module Internal.Logger where
+
+import XMonad
+import qualified XMonad.Util.ExtensibleState as XS
+import System.IO
+
+data LoggerState =
+ LoggerState {
+ logHandle :: Maybe Handle
+ }
+
+instance Read LoggerState where
+ readsPrec i s = map (\(_, s) -> (LoggerState Nothing, s)) (readsPrec i s :: [((), String)])
+
+instance Show LoggerState where
+ show _ = show ()
+
+instance ExtensionClass LoggerState where
+ initialValue = LoggerState Nothing
+
+logs :: String -> X ()
+logs s = do
+ LoggerState handle' <- XS.get
+
+ handle <-
+ case handle' of
+ Nothing -> do
+ handle <- io $ openFile "/tmp/xmonad.log" AppendMode
+ XS.put $ LoggerState (Just handle)
+ return handle
+
+ Just h -> return h
+
+ io $ do
+ hPutStrLn handle s
+ hFlush handle