packages feed

hslogger 1.2.3 → 1.2.4

raw patch · 4 files changed

+56/−36 lines, 4 filesdep ~directorydep ~mtldep ~networkPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: directory, mtl, network, old-locale, process, unix

API changes (from Hackage documentation)

+ System.Log.Logger: removeHandler :: Logger -> Logger

Files

hslogger.cabal view
@@ -1,5 +1,5 @@ Name: hslogger-Version: 1.2.3+Version: 1.2.4 License: BSD3 Maintainer: John Goerzen <jgoerzen@complete.org> Author: John Goerzen@@ -42,7 +42,7 @@         System.Log.Handler.Growl, System.Log.Handler.Log4jXML,         System.Log.Logger     Extensions: CPP, ExistentialQuantification-    Build-Depends: network < 2.5, mtl+    Build-Depends: network, mtl     if !os(windows)         Build-Depends: unix     if flag(small_base)
src/System/Log/Handler/Simple.hs view
@@ -66,7 +66,7 @@     where       writeToHandle hdl msg =           hPutStrLn hdl msg `catch` (handleWriteException hdl msg)-      handleWriteException :: Handle -> String -> IOError -> IO ()+      handleWriteException :: Handle -> String -> SomeException -> IO ()       handleWriteException hdl msg e =           let msg' = "Error writing log message: " ++ show e ++                      " (original message: " ++ msg ++ ")"
src/System/Log/Handler/Syslog.hs view
@@ -54,6 +54,7 @@ import System.Posix.Process(getProcessID) #endif import System.IO+import Control.Monad (void, when)  code_of_pri :: Priority -> Int code_of_pri p = case p of@@ -237,20 +238,8 @@  syslogFormatter :: LogFormatter SyslogHandler syslogFormatter sh (p,msg) logname =-    let code = makeCode (facility sh) p-        getpid :: IO String-        getpid = -#ifndef mingw32_HOST_OS-                     getProcessID >>= return . show-#else-                     return "windows"-#endif-        vars = [("code", return $ show code)-               ,("identity", return $ identity sh)-               ,("pid", getpid)]-        withPid = if (elem PID (options sh)) then "[$pid]" else ""-        format = "<$code>$identity"++withPid++": [$loggername/$prio] $msg"-    in varFormatter vars format sh (p,msg) logname+    let format = "[$loggername/$prio] $msg"+    in varFormatter [] format sh (p,msg) logname   instance LogHandler SyslogHandler where@@ -258,20 +247,31 @@     getLevel sh = priority sh     setFormatter sh f = sh{formatter = f}     getFormatter sh = formatter sh-    emit sh (_, msg) _ =-        let-            sendstr :: String -> IO String-            sendstr [] = return []-            sendstr omsg = do-                           sent <- case sock_type sh of-                                       Datagram -> sendTo (logsocket sh) omsg (address sh)-                                       Stream   -> send   (logsocket sh) omsg-                           sendstr (genericDrop sent omsg)-        in do-          if (elem PERROR (options sh))-               then hPutStrLn stderr msg-               else return ()-          sendstr (msg ++ "\0")-          return ()-    close sh = sClose (logsocket sh)+    emit sh (_, msg) _ = do+      when (elem PERROR (options sh)) (hPutStrLn stderr msg)+      pidPart <- getPidPart+      void $ sendstr (toSyslogFormat msg pidPart)+      where+        sendstr :: String -> IO String+        sendstr [] = return []+        sendstr omsg = do+          sent <- case sock_type sh of+                    Datagram -> sendTo (logsocket sh) omsg (address sh)+                    Stream   -> send   (logsocket sh) omsg+          sendstr (genericDrop sent omsg)+        toSyslogFormat msg pidPart =+            "<" ++ code ++ ">" ++ identity' ++ pidPart ++ ": " ++ msg ++ "\0"+        code = show (makeCode (facility sh) (priority sh))+        identity' = identity sh+        getPidPart = if elem PID (options sh)+                     then getPid >>= \pid -> return ("[" ++ pid ++ "]")+                     else return ""+        getPid :: IO String+        getPid =+#ifndef mingw32_HOST_OS+          getProcessID >>= return . show+#else+          return "windows"+#endif +    close sh = sClose (logsocket sh)
src/System/Log/Logger.hs view
@@ -178,7 +178,7 @@ but other functions won't see the changes.  To make a change global, you'll need to use 'updateGlobalLogger' or 'saveGlobalLogger'. -}-                               addHandler, setHandlers,+                               addHandler, removeHandler, setHandlers,                                getLevel, setLevel, clearLevel,                                -- ** Saving Your Changes {- | These functions commit changes you've made to loggers to the global@@ -401,11 +401,31 @@ -- | Generate IO actions for the handlers. handlerActions :: [HandlerT] -> LogRecord -> String -> [IO ()] handlerActions h lr loggername = map (callHandler lr loggername ) h-                         + -- | Add handler to 'Logger'.  Returns a new 'Logger'. addHandler :: LogHandler a => a -> Logger -> Logger addHandler h l= l{handlers = (HandlerT h) : (handlers l)} +-- | Remove a handler from the 'Logger'.  Handlers are removed in the reverse+-- order they were added, so the following property holds for any 'LogHandler'+-- @h@:+--+-- > removeHandler . addHandler h = id+--+-- If no handlers are associated with the 'Logger', it is returned unchanged.+--+-- The root logger's default handler that writes every message to stderr can+-- be removed by using this function before any handlers have been added+-- to the root logger:+--+-- > updateGlobalLogger rootLoggerName removeHandler+removeHandler :: Logger -> Logger+removeHandler l =+    case hs of [] -> l+               _  -> l{handlers = tail hs}+  where+    hs = handlers l+ -- | Set the 'Logger'\'s list of handlers to the list supplied. -- All existing handlers are removed first. setHandlers :: LogHandler a => [a] -> Logger -> Logger@@ -481,7 +501,7 @@                     Control.Exception.throw e             -- Re-raise it         in         Control.Exception.catch action handler-    + {- This function pulled in from MissingH to avoid a dep on it -} split :: Eq a => [a] -> [a] -> [[a]] split _ [] = []