logging-effect-syslog (empty) → 0.1.0.0
raw patch · 5 files changed
+100/−0 lines, 5 filesdep +basedep +bytestringdep +hsyslog
Dependencies added: base, bytestring, hsyslog, logging-effect
Files
- CHANGELOG.md +5/−0
- LICENSE +30/−0
- README.md +4/−0
- logging-effect-syslog.cabal +31/−0
- src/Control/Monad/Log/Syslog.hs +30/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for logging-effect-syslog++## 0.1.0.0++* Provides `logToSyslog`
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2021, Obsidian Systems LLC++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 Obsidian Systems LLC 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.
+ README.md view
@@ -0,0 +1,4 @@+# logging-effect-syslog+[](https://haskell.org) [](https://hackage.haskell.org/package/logging-effect-syslog) [](https://github.com/obsidiansystems/logging-effect-syslog/actions) [](https://github.com/obsidiansystems/logging-effect-syslog/blob/master/LICENSE)++A logging `Handler` for [logging-effect](https://hackage.haskell.org/package/logging-effect) that uses [hsyslog](https://hackage.haskell.org/package/hsyslog) to write log messages to a posix-compliant [syslog](https://pubs.opengroup.org/onlinepubs/9699919799/functions/syslog.html).
+ logging-effect-syslog.cabal view
@@ -0,0 +1,31 @@+cabal-version: >=1.10+name: logging-effect-syslog+version: 0.1.0.0+synopsis: Log messages to a posix system log via logging-effect+description:+ A 'Handler' for logging-effect that prints log messages to a posix system log++homepage: https://github.com/obsidiansystems/logging-effect-syslog+bug-reports:+ https://github.com/obsidiansystems/logging-effect-syslog/issues++license: BSD3+license-file: LICENSE+author: Obsidian Systems LLC+maintainer: maintainer@obsidian.systems+copyright: 2021 Obsidian Systems LLC+category: System+build-type: Simple+extra-source-files: CHANGELOG.md README.md++library+ exposed-modules: Control.Monad.Log.Syslog+ build-depends:+ base >=4.12 && < 5+ , bytestring >=0.10 && <0.12+ , hsyslog >=5 && <5.1+ , logging-effect >=1.3 && <1.5++ hs-source-dirs: src+ default-language: Haskell2010+ default-extensions: LambdaCase
+ src/Control/Monad/Log/Syslog.hs view
@@ -0,0 +1,30 @@+module Control.Monad.Log.Syslog where++import Control.Monad.IO.Class+import Control.Monad.Log+import Data.ByteString.Char8 as C8+import Data.ByteString.Unsafe (unsafeUseAsCStringLen)+import System.IO+import Data.String+import qualified System.Posix.Syslog as Posix++-- | Log messages to a posix system log. The string argument is a tag that can+-- be used to identify log messages produced by this logger.+-- You can, for instance, run @journalctl --user -t mytag@ to see log messages+-- tagged with @"mytag"@.+logToSyslog :: (MonadIO m) => String -> Handler m (WithSeverity ByteString)+logToSyslog tagstr = \(WithSeverity sev msg) ->+ liftIO $ Posix.withSyslog tagstr [Posix.DelayedOpen] Posix.User $+ unsafeUseAsCStringLen msg $+ Posix.syslog Nothing (syslogPriority sev)++syslogPriority :: Severity -> Posix.Priority+syslogPriority = \case+ Emergency -> Posix.Emergency + Alert -> Posix.Alert + Critical -> Posix.Critical + Error -> Posix.Error + Warning -> Posix.Warning + Notice -> Posix.Notice + Informational -> Posix.Info + Debug-> Posix.Debug