I am annoyed with my implementation of hslogger, when running within the GHCi REPL.
import System.IO (Handle)
import System.Log.Logger (Priority( DEBUG ), updateGlobalLogger, addHandler, setLevel, debugM)
import System.Log.Handler.Simple (fileHandler)
import System.Log.Handler (setFormatter, close)
main :: IO ()
main = do
f <- fileHandler "sample.log" DEBUG
updateGlobalLogger "Component" (addHandler f)
updateGlobalLogger "Component" (setLevel DEBUG)
debugM "Component" "This is a sample log line"
close f
It runs without exception the first time, however, on subsequent executions of main:
*** Exception: sample.log: hPutStr: illegal operation (handle is closed)
This is not experienced when I'm running the program outside of GHCi.
Am I not closing the file handle correctly with hslogger, or does GHCi keep the file handle open?
I don't the experience the same problem when opening and closing a standard file.
import System.IO (Handle, openFile, hClose, hPutStrLn, IOMode (WriteMode))
main :: IO ()
main = do
f <- openFile "sampleFile.log" WriteMode
hPutStrLn f "Hello"
hClose f