packages feed

journalctl-stream 0.3.0.0 → 0.4.0.0

raw patch · 3 files changed

+49/−16 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Systemd.Journalctl.Stream: AfterCursor :: Cursor -> StreamStart
+ Systemd.Journalctl.Stream: AtCursor :: Cursor -> StreamStart
+ Systemd.Journalctl.Stream: Lines :: Int -> StreamStart
+ Systemd.Journalctl.Stream: StartTime :: LocalTime -> StreamStart
+ Systemd.Journalctl.Stream: data StreamStart
+ Systemd.Journalctl.Stream: instance Data.Aeson.Types.ToJSON.ToJSON Systemd.Journalctl.Stream.Cursor
+ Systemd.Journalctl.Stream: instance GHC.Classes.Ord Systemd.Journalctl.Stream.Cursor
- Systemd.Journalctl.Stream: entryStream :: (MonadResource m, MonadThrow m) => Maybe String -> Int -> ConduitT i Entry m ()
+ Systemd.Journalctl.Stream: entryStream :: (MonadResource m, MonadThrow m) => StreamStart -> ConduitT i Entry m ()

Files

changelog.md view
@@ -1,3 +1,10 @@+## 0.4.0.0+* Changed arguments of `entryStream`. It now takes a value of type+  `StreamStart`. This value can be used to indicate where the stream+  will start. The unit filter argument is gone. Instead, use conduit+  functions to filter the stream.+* New instances for `Cursor`: `Ord`, `ToJSON`.+ ## 0.3.0.0 * Fix for fields: `entryPID`, `entryProcess`, `entryExecutable`.   They are optional now, as they should have been.
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.3.0.0+version: 0.4.0.0 author: Daniel Casanueva (daniel.casanueva `at` proton.me) maintainer: Daniel Casanueva (daniel.casanueva `at` proton.me) license: MIT
lib/Systemd/Journalctl/Stream.hs view
@@ -12,6 +12,7 @@     Entry (..)   , Cursor     -- * Streaming+  , StreamStart (..)   , entryStream     -- * Exceptions   , Exception@@ -25,12 +26,15 @@ -- text import Data.Text (Text) import Data.Text.Encoding (encodeUtf8)+import Data.Text qualified as Text -- aeson-import Data.Aeson (FromJSON, (.:), (.:?))+import Data.Aeson (FromJSON, (.:), (.:?), ToJSON) import Data.Aeson qualified as JSON -- time import Data.Time.Clock (secondsToNominalDiffTime) import Data.Time.Clock.POSIX (POSIXTime)+import Data.Time.LocalTime (LocalTime)+import Data.Time.Format (formatTime, defaultTimeLocale) -- process import System.Process qualified as System -- conduit@@ -41,11 +45,18 @@ -- | A cursor is an opaque text string that uniquely describes --   the position of an entry in the journal and is portable --   across machines, platforms and journal files.-newtype Cursor = Cursor Text deriving (Eq, Show)+--+--   The 'Ord' instance does not order by time. Given two entries+--   @e1@ and @e2@, @e1@ having an earlier timestamp than @e2@ doesn't+--   mean that @entryCursor e1 < entryCursor e2@.+newtype Cursor = Cursor Text deriving (Eq, Ord, Show)  instance FromJSON Cursor where   parseJSON = JSON.withText "Cursor" $ pure . Cursor +instance ToJSON Cursor where+  toJSON (Cursor t) = JSON.String t+ -- | A journal entry. data Entry = Entry   { -- | Process ID.@@ -101,22 +112,37 @@  instance Base.Exception Exception where --- | Stream of journal entries.+-- | Where to start a stream.+data StreamStart =+    -- | Start from the given time.+    StartTime LocalTime+    -- | Start from the given number of lines back.+  | Lines Int+    -- | Start /at/ the given cursor.+  | AtCursor Cursor+    -- | Start /after/ the given cursor.+  | AfterCursor Cursor++-- | Translate a 'StreamStart' insto the arguments required+--   for journalctl.+streamStartArgs :: StreamStart -> [String]+streamStartArgs (StartTime t) =+  [ "--since", formatTime defaultTimeLocale "%F %T" t ]+streamStartArgs (Lines n) =+  [ "--lines" , show n ]+streamStartArgs (AtCursor (Cursor t)) =+  [ "--cursor", Text.unpack t ]+streamStartArgs (AfterCursor (Cursor t)) =+  [ "--after-cursor", Text.unpack t ]++-- | Stream all journal entries starting from the given point. entryStream   :: (MonadResource m, MonadThrow m)-  => Maybe String -- ^ Filter by unit name.-  -> Int -- ^ Number of previous messages to stream.-  -> ConduitT i Entry m ()-entryStream munit n =+  => StreamStart -- ^ Where to start streaming entries.+  -> ConduitT i Entry m () -- ^ Stream of journal entries.+entryStream start =   let args :: [String]-      args =-        [ "--follow"-        , "--lines"-        , show n-        , "--output"-        , "json"-          ] ++-        (maybe [] (\unit -> ["--unit", unit]) munit)+      args = streamStartArgs start ++ [ "--follow", "--output", "json" ]       hdl :: IO Handle       hdl = fmap (\(_, h, _, _) -> fromJust h)           $ System.createProcess