monad-logger-syslog 0.1.1.1 → 0.1.2.0
raw patch · 4 files changed
+47/−16 lines, 4 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- System.Log.MonadLogger.Syslog: runSyslogLoggingT :: MonadIO m => LoggingT m a -> m a
+ System.Log.MonadLogger.Syslog: runSyslogLoggingT :: LoggingT m a -> m a
Files
- Control/Monad/Logger/Syslog.hs +5/−3
- README.md +6/−4
- System/Log/MonadLogger/Syslog.hs +34/−7
- monad-logger-syslog.cabal +2/−2
Control/Monad/Logger/Syslog.hs view
@@ -8,14 +8,16 @@ Portability : POSIX Example:-```++@ import Control.Monad.Logger ( logDebugN ) import Control.Monad.Logger.Syslog ( runSyslogLoggingT ) main :: IO () main = runSyslogLoggingT (logDebugN "HELLO!")-```-|-}+@++-} module Control.Monad.Logger.Syslog ( module System.Log.MonadLogger.Syslog ) where
README.md view
@@ -9,8 +9,10 @@ ## Usage (example) - import Control.Monad.Logger ( logDebugN )- import Control.Monad.Logger.Syslog ( runSyslogLoggingT )+```haskell+import Control.Monad.Logger ( logDebugN )+import Control.Monad.Logger.Syslog ( runSyslogLoggingT ) - main :: IO ()- main = runSyslogLoggingT (logDebugN "HELLO!")+main :: IO ()+main = runSyslogLoggingT (logDebugN "HELLO!")+```
System/Log/MonadLogger/Syslog.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} module System.Log.MonadLogger.Syslog@@ -8,31 +9,49 @@ ) where -import Control.Monad.IO.Class (MonadIO ()) import Control.Monad.Logger import System.Posix.Syslog import Data.Text (unpack) import System.Log.FastLogger (fromLogStr)+#if MIN_VERSION_hsyslog(4,0,0)+#else import qualified Data.ByteString.Char8 as BS8+#endif -runSyslogLoggingT :: MonadIO m => LoggingT m a -> m a+-- | Runs a 'LoggingT', sending its output to the syslog. The logs+-- are formatted the same as 'runStdoutLoggingT', but the 'LogLevel'+-- is converted to a syslog priority value (but still included in the+-- log message).+runSyslogLoggingT :: LoggingT m a -> m a runSyslogLoggingT = (`runLoggingT` syslogOutput) --- TODO: useSyslog allows giving a source name and should be more efficient--- But it assumes IO--- Perhaps should use mmorph to generalize IO to MonadIO+-- TODO: useSyslog allows giving a source name and should be more+-- efficient But it assumes IO. Perhaps MonadBaseControl should be+-- used to generalize it.+--+-- Note that this probably shouldn't be the default implementation,+-- because these settings are process-wide:+-- https://hackage.haskell.org/package/hsyslog-2.0/docs/System-Posix-Syslog.html#v:withSyslog+--+-- So, concurrent use of this would step on eachother. {- runSyslogLoggingT :: MonadIO m => String -> LoggingT m a -> m a runSyslogLoggingT source action = useSyslog source (runLoggingT action defaultSyslogOutput) -} +-- | Same as 'defaultSyslogOutput'. syslogOutput :: Loc -> LogSource -> LogLevel -> LogStr -> IO () syslogOutput = defaultSyslogOutput +-- | This invokes 'formattedSyslogOutput' with 'defaultLogStr'. This+-- means that the resulting log messages are the same as the default+-- format used by "Control.Monad.Logger". defaultSyslogOutput :: Loc -> LogSource -> LogLevel -> LogStr -> IO () defaultSyslogOutput = formattedSyslogOutput defaultLogStr +-- | Given a "Control.Monad.Logger" log formatter, this writes the log+-- to the syslog, formattedSyslogOutput :: (Loc -> LogSource -> LogLevel -> LogStr -> LogStr) -> Loc -> LogSource@@ -40,8 +59,16 @@ -> LogStr -> IO () formattedSyslogOutput f l s level msg =- syslog (levelToPriority level)- (BS8.unpack (fromLogStr (f l s level msg)))+#if MIN_VERSION_hsyslog(4,0,0)+ withSyslog undefined $ \syslog ->+ syslog USER+ (levelToPriority level)+ (fromLogStr $ f l s level msg)+#else+ syslog+ (levelToPriority level)+ (BS8.unpack $ fromLogStr $ f l s level msg)+#endif levelToPriority :: LogLevel -> Priority levelToPriority LevelDebug = Debug
monad-logger-syslog.cabal view
@@ -1,5 +1,5 @@ name: monad-logger-syslog-version: 0.1.1.1+version: 0.1.2.0 synopsis: syslog output for monad-logger description: syslog output for monad-logger homepage: https://github.com/fpco/monad-logger-syslog@@ -21,7 +21,7 @@ exposed-modules: Control.Monad.Logger.Syslog System.Log.MonadLogger.Syslog ghc-options: -Wall- build-depends: base >=4.6 && <5+ build-depends: base >=4.7 && <5 , bytestring , fast-logger , hsyslog