packages feed

simple-log-syslog (empty) → 0.1.0.0

raw patch · 4 files changed

+105/−0 lines, 4 filesdep +basedep +hsyslogdep +simple-logsetup-changed

Dependencies added: base, hsyslog, simple-log, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Alexandr `voidex` Ruchkin++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 Alexandr `voidex` Ruchkin nor the names of other+      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+OWNER 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ simple-log-syslog.cabal view
@@ -0,0 +1,22 @@+name:                simple-log-syslog+version:             0.1.0.0+synopsis:            Syslog backend for simple-log+-- description:         +homepage:            http://github.com/mvoidex/simple-log-syslog+license:             BSD3+license-file:        LICENSE+author:              Alexandr `voidex` Ruchkin+maintainer:          voidex@live.com+Category:             Logging+build-type:          Simple+cabal-version:       >=1.8++library+  hs-source-dirs: src  +  build-depends:+    base >= 4.6 && < 6,+    text == 0.11.*,+    simple-log == 0.2.*,+    hsyslog == 1.*+  exposed-modules:+    System.Log.Syslog
+ src/System/Log/Syslog.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE OverloadedStrings #-}++-- | Module provides syslog logger for simple-log+--+-- >yourFunction :: MonadLog m => m ()+-- >yourFunction = scope "your" $ log Trace "Hello"+-- >+-- >run :: IO ()+-- >run = do+-- >    l <- newLog (fileCfg "log.cfg" 60) [syslog "name"]+-- >    withLog l yourFunction+--+module System.Log.Syslog (+    SyslogMessage(..),+    syslogMsg,+    toSyslog, toSyslog_,+    syslog, syslog_+    ) where++import System.Posix.Syslog (Option(..), Facility(..))+import qualified System.Posix.Syslog as Syslog+import qualified Data.Text as T+import System.Log.Base++data SyslogMessage = SyslogMessage {+    syslogPriority :: Syslog.Priority,+    syslogMessage :: String }+        deriving (Eq, Show)++syslogMsg :: Converter SyslogMessage+syslogMsg (Message _ lvl path msg) = SyslogMessage (priority lvl) $ T.unpack $ T.concat [T.intercalate "/" path, "> ", msg] where+    priority Trace = Syslog.Debug+    priority Debug = Syslog.Debug+    priority Info = Syslog.Info+    priority Warning = Syslog.Warning+    priority Error = Syslog.Error+    priority Fatal = Syslog.Critical++toSyslog :: String -> [Option] -> Facility -> Consumer SyslogMessage+toSyslog name ops facility = Consumer withSys where+    withSys f = Syslog.withSyslog name ops facility $ f $ \(SyslogMessage p str) -> Syslog.syslog p str++toSyslog_ :: String -> Consumer SyslogMessage+toSyslog_ name = Consumer withSys where+    withSys f = Syslog.useSyslog name $ f $ \(SyslogMessage p str) -> Syslog.syslog p str++syslog :: String -> [Option] -> Facility -> Logger+syslog name ops facility = logger syslogMsg (toSyslog name ops facility)++syslog_ :: String -> Logger+syslog_ name = logger syslogMsg (toSyslog_ name)