packages feed

katip-syslog (empty) → 0.1.0.0

raw patch · 6 files changed

+133/−0 lines, 6 filesdep +aesondep +basedep +bytestringsetup-changed

Dependencies added: aeson, base, bytestring, hsyslog, katip, katip-syslog, string-conv, text

Files

+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2017, IRIS Connect Ltd+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+  list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+  this list of conditions and the following disclaimer in the documentation+  and/or other materials provided with the distribution.++* Neither the name of the copyright holder nor the names of its+  contributors may be used to endorse or promote products derived from+  this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,3 @@+# katip-syslog++This Haskell package provides a simple Katip Scribe which logs to syslog.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ katip-syslog.cabal view
@@ -0,0 +1,46 @@+name:                katip-syslog+version:             0.1.0.0+synopsis:            Syslog Katip Scribe+description:         A simple Katip Scribe which logs to syslog+homepage:            https://github.com/iconnect/katip-syslog#readme+license:             BSD3+license-file:        LICENSE+author:              Alfredo Di Napoli+maintainer:          alfredo@irisconnect.co.uk+copyright:           2017 IRIS Connect Engineering Team+category:            Web+build-type:          Simple+extra-source-files:  README.md+bug-reports:         http://github.com/iconnect/katip-syslog/issues++cabal-version:       >=1.10++Source-Repository head+    type:               git+    location:           https://github.com/iconnect/katip-syslog.git++library+  hs-source-dirs:      src+  exposed-modules:     Katip.Scribes.Syslog+  build-depends:       base  >= 4.7 && < 5+                     , katip < 0.4.0.0+                     , hsyslog >= 4 && < 5+                     , text < 1.3.0.0+                     , string-conv < 0.2+                     , aeson < 2.0.0.0+                     , bytestring < 0.12+  ghc-options:         -Wall+  default-language:    Haskell2010++test-suite katip-syslog-test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:       base+                     , katip-syslog+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/iconnect/katip-syslog
+ src/Katip/Scribes/Syslog.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE RecordWildCards #-}+module Katip.Scribes.Syslog+    ( mkSyslogScribe+    ) where+++import           Control.Exception (try, SomeException)+import           Control.Monad+import           Data.Aeson (encode)+import           Data.ByteString.Lazy (ByteString)+import           Data.String.Conv+import qualified Data.Text as T+import           Katip.Core+import           System.Posix.Syslog++--------------------------------------------------------------------------------+-- | A syslog `Scribe` which respects the main Katip's guidelines.+-- Returns a tuple containing the `Scribe` and a finaliser.+mkSyslogScribe :: Namespace -> Severity -> Verbosity -> IO (Scribe, IO ())+mkSyslogScribe ns sev verb = do+  let identifier = T.intercalate "." (unNamespace ns)+  let cfg = defaultConfig {  identifier   = toS identifier+                           , options      = [PID, CONS, ODELAY, NDELAY]+                           , priorityMask = NoMask -- Katip does the masking for us.+                           }+  let scribe = Scribe $ \ i@Item{..} -> do+                            when (permitItem sev i) $ do+                              res <- try $ withSyslog cfg $ \syslog -> syslog USER (toSyslogPriority _itemSeverity) (toS $ formatItem verb i)+                              case res of+                                Left (e :: SomeException) -> putStrLn (show e)+                                Right () -> return ()+  return (scribe, return ())++--------------------------------------------------------------------------------+-- | Syslog won't handle correctly things like newlines, so it's programmer's+-- responsibility to escape those.+formatItem :: LogItem a => Verbosity -> Item a -> ByteString+formatItem verb = encode . itemJson verb++--------------------------------------------------------------------------------+toSyslogPriority :: Severity -> Priority+toSyslogPriority DebugS      =  Debug+toSyslogPriority InfoS       =  Info+toSyslogPriority NoticeS     =  Notice+toSyslogPriority WarningS    =  Warning+toSyslogPriority ErrorS      =  Error+toSyslogPriority CriticalS   =  Critical+toSyslogPriority AlertS      =  Alert+toSyslogPriority EmergencyS  =  Emergency
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"