monad-logger-syslog 0.1.4.0 → 0.1.5.0
raw patch · 4 files changed
+65/−45 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- System.Log.MonadLogger.Syslog: defaultSyslogOutput :: Loc -> LogSource -> LogLevel -> LogStr -> IO ()
- System.Log.MonadLogger.Syslog: formattedSyslogOutput :: (Loc -> LogSource -> LogLevel -> LogStr -> LogStr) -> Loc -> LogSource -> LogLevel -> LogStr -> IO ()
- System.Log.MonadLogger.Syslog: syslogOutput :: Loc -> LogSource -> LogLevel -> LogStr -> IO ()
+ System.Log.MonadLogger.Syslog: Auth :: Facility
+ System.Log.MonadLogger.Syslog: Cron :: Facility
+ System.Log.MonadLogger.Syslog: Daemon :: Facility
+ System.Log.MonadLogger.Syslog: Kernel :: Facility
+ System.Log.MonadLogger.Syslog: LPR :: Facility
+ System.Log.MonadLogger.Syslog: Local0 :: Facility
+ System.Log.MonadLogger.Syslog: Local1 :: Facility
+ System.Log.MonadLogger.Syslog: Local2 :: Facility
+ System.Log.MonadLogger.Syslog: Local3 :: Facility
+ System.Log.MonadLogger.Syslog: Local4 :: Facility
+ System.Log.MonadLogger.Syslog: Local5 :: Facility
+ System.Log.MonadLogger.Syslog: Local6 :: Facility
+ System.Log.MonadLogger.Syslog: Local7 :: Facility
+ System.Log.MonadLogger.Syslog: Mail :: Facility
+ System.Log.MonadLogger.Syslog: News :: Facility
+ System.Log.MonadLogger.Syslog: UUCP :: Facility
+ System.Log.MonadLogger.Syslog: User :: Facility
+ System.Log.MonadLogger.Syslog: data Facility
+ System.Log.MonadLogger.Syslog: runCustomSyslogLoggingT :: String -> Facility -> LoggingT m a -> m a
Files
- ChangeLog.md +4/−0
- README.md +12/−0
- System/Log/MonadLogger/Syslog.hs +47/−43
- monad-logger-syslog.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.1.5.0++* Allow custom logger name and facility.+ ## 0.1.4.0 * Support for hsyslog-5
README.md view
@@ -9,10 +9,22 @@ ## Usage (example) +### Default to syslog `user` facility with name `hslogger`+ ```haskell import Control.Monad.Logger ( logDebugN ) import Control.Monad.Logger.Syslog ( runSyslogLoggingT ) main :: IO () main = runSyslogLoggingT (logDebugN "HELLO!")+```++### Log under `Local1` facility with name `mylogger`++```haskell+import Control.Monad.Logger ( logDebugN )+import Control.Monad.Logger.Syslog ( runCustomSyslogLoggingT )++main :: IO ()+main = runCustomSyslogLoggingT "mylogger" Local1 (logDebugN "HELLO!") ```
System/Log/MonadLogger/Syslog.hs view
@@ -3,73 +3,77 @@ module System.Log.MonadLogger.Syslog ( runSyslogLoggingT- , syslogOutput- , defaultSyslogOutput- , formattedSyslogOutput+ , runCustomSyslogLoggingT+ , System.Posix.Syslog.Facility(..) ) where import Control.Monad.Logger+import Data.Text ( unpack )+import System.Log.FastLogger ( fromLogStr ) import System.Posix.Syslog-import Data.Text (unpack)-import System.Log.FastLogger (fromLogStr)+ #if MIN_VERSION_hsyslog(5,0,0) import qualified Data.ByteString.Unsafe as BSU-#elif MIN_VERSION_hsyslog(4,0,0) #else import qualified Data.ByteString.Char8 as BS8 #endif --- | 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).+-- | Runs a 'LoggingT' action, sending its output to Syslog.+-- Logging will use service name (logger "tag") 'hslogger',+-- and Syslog facility 'User'. Log lines will have the same+-- format as 'runStdoutLoggingT', but the 'LogLevel' will+-- be converted to the matching Syslog priority value, and+-- will be included in the logged 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 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)--}+#if MIN_VERSION_hsyslog(5,0,0)+runSyslogLoggingT = runCustomSyslogLoggingT "hslogger" User+#else+runSyslogLoggingT = runCustomSyslogLoggingT "hslogger" USER+#endif --- | Same as 'defaultSyslogOutput'.-syslogOutput :: Loc -> LogSource -> LogLevel -> LogStr -> IO ()-syslogOutput = defaultSyslogOutput+-- | Like 'runSyslogLoggingT', but specifying desired service+-- name -- (logger "tag") and Syslog facility.+runCustomSyslogLoggingT :: String -- ^ Logger tag.+ -> Facility -- ^ Syslog facility.+ -> LoggingT m a+ -> m a+runCustomSyslogLoggingT n f = (`runLoggingT` defaultSyslogOutput n f) --- | 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+-- 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 :: String -- Logger tag+ -> Facility -- Syslog facility+ -> Loc+ -> LogSource+ -> LogLevel+ -> LogStr+ -> IO ()+defaultSyslogOutput n f = formattedSyslogOutput n f defaultLogStr --- | Given a "Control.Monad.Logger" log formatter, this writes the log--- to the syslog,-formattedSyslogOutput :: (Loc -> LogSource -> LogLevel -> LogStr -> LogStr)+-- Given a "Control.Monad.Logger" log formatter, this writes+-- the log to the syslog,+formattedSyslogOutput :: String -- Logger tag+ -> Facility -- Syslog facility+ -> (Loc -> LogSource -> LogLevel -> LogStr -> LogStr) -> Loc -> LogSource -> LogLevel -> LogStr -> IO ()-formattedSyslogOutput f l s level msg =+formattedSyslogOutput name facility f l s level msg = #if MIN_VERSION_hsyslog(5,0,0)- withSyslog "hsyslog" [DelayedOpen] User $+ withSyslog name [DelayedOpen] facility $ BSU.unsafeUseAsCStringLen (fromLogStr $ f l s level msg) $ syslog- (Just User)+ (Just facility) (levelToPriority level) #elif MIN_VERSION_hsyslog(4,0,0)- withSyslog defaultConfig $ \syslog ->- syslog USER+ withSyslog defaultConfig { identifier = BS8.pack name+ , defaultFacility = facility+ } $ \syslog ->+ syslog facility (levelToPriority level) (fromLogStr $ f l s level msg) #else@@ -89,4 +93,4 @@ "Alert" -> Alert "Critical" -> Critical "Notice" -> Notice- _ -> error $ "unknown log level: " ++ unpack level+ _ -> error $ "unknown log level: " ++ unpack level
monad-logger-syslog.cabal view
@@ -1,12 +1,12 @@ name: monad-logger-syslog-version: 0.1.4.0+version: 0.1.5.0 synopsis: syslog output for monad-logger description: syslog output for monad-logger homepage: https://github.com/fpco/monad-logger-syslog license: MIT license-file: LICENSE author: Greg Weber & FP Complete Developers-maintainer: devs@fpcomplete.com+maintainer: Ernesto Hernández-Novich <haskell@iamemhn.link> category: Logging build-type: Simple extra-source-files: README.md ChangeLog.md