Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra documentation for the journalEntryRealtime field #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libsystemd-journal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ library
, pipes-safe ^>= 2.3.1
, text ^>= 1.2.5 || ^>= 2.0
, transformers ^>= 0.5.6 || ^>= 0.6
, time >= 1 && <= 2
, unix-bytestring ^>= 0.3.6 || ^>= 0.4
, vector ^>= 0.12.3 || ^>= 0.13
, uuid ^>= 1.3.13
Expand Down
15 changes: 15 additions & 0 deletions src/Systemd/Journal.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Systemd.Journal
, Direction(..)
, JournalEntry, JournalEntryCursor
, journalEntryFields, journalEntryCursor, journalEntryRealtime
, realtimeToUTCTime
, JournalFlag (..)
, Filter (..)
) where
Expand All @@ -49,6 +50,7 @@ import Data.List (foldl')
import Data.Monoid (Monoid, mappend, mempty)
import Data.Semigroup (Semigroup)
import Data.String (IsString (..))
import Data.Time (UTCTime)
import Data.Typeable (Typeable)
import Data.Word
import Foreign (Ptr, alloca, free, peek, throwIfNeg)
Expand All @@ -62,6 +64,7 @@ import qualified Data.Generics.Uniplate.Operations as Uniplate
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Data.Time.Clock.System as Time
import qualified Data.UUID as UUID
import qualified Data.Vector.Storable as V
import qualified Pipes as Pipes
Expand Down Expand Up @@ -276,9 +279,21 @@ data JournalEntry = JournalEntry
, journalEntryRealtime :: Word64
-- ^ The time (in microseconds since the epoch) when this journal entry was
-- received by the systemd journal.
-- Use 'realtimeToUTCTime' to get the 'UTCTime' version.
--
-- Note that an earlier timestamp can usually be found in the
-- _SOURCE_REALTIME_TIMESTAMP field.
}
deriving (Eq, Show)

-- | Convert a 'JournalEntry' realtime to 'UTCTime'
realtimeToUTCTime :: Word64 -> UTCTime
realtimeToUTCTime realtime =
Time.systemToUTCTime $ Time.MkSystemTime (fromIntegral seconds) (fromIntegral (micro * 1000))

where
(seconds, micro) = realtime `divMod` 1000000

--------------------------------------------------------------------------------
-- | A logical expression to filter journal entries when reading the journal.
data Filter
Expand Down