module Neovim.Log (
disableLogger,
withLogger,
module System.Log.Logger,
) where
import Control.Exception
import System.Log.Formatter (simpleLogFormatter)
import System.Log.Handler (setFormatter)
import System.Log.Handler.Simple
import System.Log.Logger
disableLogger :: IO a -> IO a
disableLogger action = do
updateGlobalLogger rootLoggerName removeHandler
action
withLogger :: FilePath -> Priority -> IO a -> IO a
withLogger fp p action = bracket
setupRootLogger
(\fh -> closeFunc fh (privData fh))
(const action)
where
setupRootLogger = do
disableLogger (return ())
fh <- fileHandler fp p
let fh' = setFormatter fh (simpleLogFormatter "[$loggername : $prio] $msg")
updateGlobalLogger rootLoggerName (setLevel p . addHandler fh')
logM "Neovim.Debug" DEBUG $
unwords ["Initialized root looger with priority", show p, "and file: ", fp]
return fh'