packages feed

journalctl-stream 0.5.0.0 → 0.6.0.0

raw patch · 3 files changed

+23/−6 lines, 3 filesdep +bytestringPVP ok

version bump matches the API change (PVP)

Dependencies added: bytestring

API changes (from Hackage documentation)

- Systemd.Journalctl.Stream: Entry :: Maybe ProcessID -> Text -> Maybe Text -> Maybe Text -> Maybe FilePath -> Cursor -> POSIXTime -> Maybe Text -> Maybe Text -> Entry
+ Systemd.Journalctl.Stream: Entry :: Maybe ProcessID -> Text -> Maybe Text -> Maybe Text -> Maybe FilePath -> Cursor -> POSIXTime -> Maybe Text -> Maybe (Either ByteString Text) -> Entry
- Systemd.Journalctl.Stream: [entryMessage] :: Entry -> Maybe Text
+ Systemd.Journalctl.Stream: [entryMessage] :: Entry -> Maybe (Either ByteString Text)

Files

changelog.md view
@@ -1,3 +1,6 @@+## 0.6.0.0+* Add support for bytestring messages in `entryMessage`.+ ## 0.5.0.0 * Fix for field: `entryMessage`. This field is not always present. 
journalctl-stream.cabal view
@@ -2,7 +2,7 @@ category: System synopsis: Stream logs using journalctl. description: Stream logs using journalctl. Check the documentation for more details.-version: 0.5.0.0+version: 0.6.0.0 author: Daniel Casanueva (daniel.casanueva `at` proton.me) maintainer: Daniel Casanueva (daniel.casanueva `at` proton.me) license: MIT@@ -16,5 +16,5 @@   default-language: Haskell2010   default-extensions: ImportQualifiedPost, OverloadedStrings   ghc-options: -Wall -Wunused-packages-  build-depends: base < 4.18, aeson, conduit, process, text, time+  build-depends: base < 4.18, aeson, conduit, process, text, time, bytestring   exposed-modules: Systemd.Journalctl.Stream
lib/Systemd/Journalctl/Stream.hs view
@@ -23,13 +23,19 @@ import Data.Maybe (fromJust) import Control.Exception qualified as Base import System.Posix.Types (CPid (..), ProcessID)+import Data.Foldable (toList) -- text import Data.Text (Text) import Data.Text.Encoding (encodeUtf8) import Data.Text qualified as Text+-- bytestring+import Data.ByteString (ByteString)+import Data.ByteString qualified as ByteString -- aeson-import Data.Aeson (FromJSON, (.:), (.:?), ToJSON)+import Data.Aeson (FromJSON, parseJSON, (.:), (.:?), ToJSON) import Data.Aeson qualified as JSON+import Data.Aeson.Types qualified as JSON+import Data.Aeson.KeyMap qualified as KeyMap -- time import Data.Time.Clock (secondsToNominalDiffTime) import Data.Time.Clock.POSIX (POSIXTime)@@ -75,8 +81,8 @@   , entryTimestamp :: POSIXTime     -- | Unit name, if present.   , entryUnit :: Maybe Text-    -- | Entry message.-  , entryMessage :: Maybe Text+    -- | Entry message. It may come in binary or textual format.+  , entryMessage :: Maybe (Either ByteString Text)     } deriving Show  -- | Utility type to parse values (mainly numbers) that are received@@ -105,7 +111,15 @@     <*> o .: "__CURSOR"     <*> (secondsToNominalDiffTime . (/1000000) . asText <$> o .: "__REALTIME_TIMESTAMP")     <*> o .:? "UNIT"-    <*> o .:? "MESSAGE"+    <*> messageParser o++messageParser :: JSON.Object -> JSON.Parser (Maybe (Either ByteString Text))+messageParser obj =+  case KeyMap.lookup "MESSAGE" obj of+    Just (JSON.String t) -> pure $ Just $ Right t+    Just (JSON.Array arr) -> Just . Left . ByteString.pack <$> mapM parseJSON (toList arr)+    Nothing -> pure Nothing+    _ -> fail $ "Couldn't parse MESSAGE. Expected String or Array."  -- | Exception raised while streaming entries from journalctl. data Exception = JSONError String deriving Show