logging-facade-syslog (empty) → 1
raw patch · 4 files changed
+136/−0 lines, 4 filesdep +basedep +hsyslogdep +logging-facadesetup-changed
Dependencies added: base, hsyslog, logging-facade
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- logging-facade-syslog.cabal +36/−0
- src/System/Logging/Facade/Syslog.hs +68/−0
+ LICENSE view
@@ -0,0 +1,30 @@+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.++ * The names of its contributors may not 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
+ logging-facade-syslog.cabal view
@@ -0,0 +1,36 @@+-- This file has been generated from package.yaml by hpack version 0.17.0.+--+-- see: https://github.com/sol/hpack++name: logging-facade-syslog+version: 1+synopsis: A logging back-end to syslog(3) for the logging-facade library+description: A simple "System.Logging.Facade" back-end for @syslog(3)@ as specified in <http://pubs.opengroup.org/onlinepubs/9699919799/functions/syslog.html POSIX.1-2008>.+category: System+stability: stable+homepage: https://github.com/peti/logging-facade-syslog#readme+bug-reports: https://github.com/peti/logging-facade-syslog/issues+author: Peter Simons+maintainer: Peter Simons <simons@cryp.to>+license: BSD3+license-file: LICENSE+tested-with: GHC > 7 && < 8.1+build-type: Simple+cabal-version: >= 1.10++source-repository head+ type: git+ location: https://github.com/peti/logging-facade-syslog++library+ hs-source-dirs:+ src+ build-depends:+ base < 5+ , logging-facade+ , hsyslog == 5.*+ exposed-modules:+ System.Logging.Facade.Syslog+ other-modules:+ Paths_logging_facade_syslog+ default-language: Haskell2010
+ src/System/Logging/Facade/Syslog.hs view
@@ -0,0 +1,68 @@+{- |+ Maintainer: simons@cryp.to+ Stability: provisional+ Portability: POSIX++ A simple "System.Logging.Facade" back-end for @syslog(3)@ as specified in+ <http://pubs.opengroup.org/onlinepubs/9699919799/functions/syslog.html POSIX.1-2008>.+-}++module System.Logging.Facade.Syslog where++import System.Logging.Facade.Sink ( LogSink )+import System.Logging.Facade.Types ( LogRecord(LogRecord), LogLevel(..), Location(..) )+import System.Posix.Syslog ( Priority(..), Facility, syslog )+import Foreign.C.String ( withCStringLen )++-- | Pass this value to 'System.Logging.Facade.Sink.setLogSink' to switch+-- logging to 'syslog'. Messages of all priorities will be logged in the+-- processes' default syslog facility --- typically 'System.Posix.Syslog.User'.+-- If these default settings don't fit your needs, consider using 'syslogSink'+-- or call 'System.Posix.Syslog.withSyslog' or a similar funtion to configure+-- the system's @syslog@ implementation appropriately.+--+-- @+-- syslogSink = syslogSink' showWithLocation Nothing+-- @++syslogSink :: LogSink+syslogSink = syslogSink' showWithLocation Nothing++-- | A variant of 'syslogSink' that allows you to control how the location+-- information provided by @logger-facade@ is baked into the log message and+-- which @syslog@ 'Facility' will be used. If no explicit facility is set,+-- messages go out with whatever the process default is --- typically+-- 'System.Posix.Syslog.User'.++syslogSink' :: (Maybe Location -> String -> String) -> Maybe Facility -> LogSink+syslogSink' fmtMessage facil (LogRecord lvl loc msg) =+ withCStringLen (fmtMessage loc msg) (syslog facil (mapPrio lvl))+ where+ mapPrio :: LogLevel -> Priority+ mapPrio TRACE = Debug+ mapPrio DEBUG = Debug+ mapPrio INFO = Info+ mapPrio WARN = Warning+ mapPrio ERROR = Error++-- | The default message formatter used by 'syslogSink'. It will append the+-- location of the message to the string such that running+--+-- @+-- info "Hello, world."+-- @+--+-- yields:+--+-- @+-- May 15 10:59:41 myhost ghc[28074]: Hello, world. (from package \"interactive\", module \"Ghci2\", file \"\<interactive\>\", line 32, and column 1+-- @++showWithLocation :: Maybe Location -> String -> String+showWithLocation Nothing msg = msg+showWithLocation (Just loc) msg = showString msg+ . showString " (from package " . shows (locationPackage loc)+ . showString ", module " . shows (locationModule loc)+ . showString ", file " . shows (locationFile loc)+ . showString ", line " . shows (locationLine loc)+ . showString ", and column " $ show (locationColumn loc)