aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/Logger.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-04-10 13:26:16 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-10-09 12:19:46 -0600
commita652c330707e2e9bbe963e01af79ce730cf3452e (patch)
tree047655195f50efcbd51db8f825acf589dc6abead /src/Rahm/Desktop/Logger.hs
parent381a3e5a00813314249bb74b5460f5ff5a4006bb (diff)
downloadrde-a652c330707e2e9bbe963e01af79ce730cf3452e.tar.gz
rde-a652c330707e2e9bbe963e01af79ce730cf3452e.tar.bz2
rde-a652c330707e2e9bbe963e01af79ce730cf3452e.zip
Rename Internal to Rahm.Desktop
Diffstat (limited to 'src/Rahm/Desktop/Logger.hs')
-rw-r--r--src/Rahm/Desktop/Logger.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Rahm/Desktop/Logger.hs b/src/Rahm/Desktop/Logger.hs
new file mode 100644
index 0000000..c73942f
--- /dev/null
+++ b/src/Rahm/Desktop/Logger.hs
@@ -0,0 +1,32 @@
+module Rahm.Desktop.Logger where
+
+import XMonad
+import qualified XMonad.Util.ExtensibleState as XS
+import System.IO
+
+import Rahm.Desktop.NoPersist
+
+newtype LoggerState =
+ LoggerState {
+ logHandle :: Maybe (NoPersist Handle)
+ }
+
+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 $ NoPersist handle
+ return handle
+
+ Just (NoPersist h) -> return h
+
+ io $ do
+ hPutStrLn handle s
+ hFlush handle