unclogging-0.1.0.1: src/Unclog/Common.hs
module Unclog.Common
( -- * commonly used types
LogEntry (..)
-- ** types that are lifted by template haskell
, LogLevel (..)
, Location (..)
, Position (..)
-- * channels for publish / subscribe
, PLogChan (..)
, SLogChan (..)
)
where
import Chronos.Types (Time)
import Data.ByteString (StrictByteString)
import Data.Text (Text)
import GHC.Generics (Generic)
import Language.Haskell.TH.Syntax (Lift)
import UnliftIO
-- | the datatype to communicate between a log source and a logging backend
data LogEntry = MkLogEntry
{ level :: {-# UNPACK #-} !LogLevel
-- ^ the log level
, timestamp :: {-# UNPACK #-} !Time
-- ^ the time at which the log entry was emitted
, location :: {-# UNPACK #-} !Location
, payload :: {-# UNPACK #-} !StrictByteString
-- ^ the payload, this is the unstructure part of the log, converting from the structured to the unstructured
-- version is the task of the logging frontend
}
deriving stock (Eq, Ord, Show, Generic)
-- | a loglevel
data LogLevel = Debug | Info | Warn | Fatal
deriving stock (Eq, Ord, Show, Generic, Lift)
-- | a source code position
data Position = MkPosition
{ posLeft :: {-# UNPACK #-} !Int
, posRight :: {-# UNPACK #-} !Int
}
deriving stock (Eq, Ord, Show, Generic, Lift)
-- | the code location at which the log entry was generated
data Location = MkLocation
{ locpkg :: {-# UNPACK #-} !Text
-- ^ the package in which the log entry was generated
, locmod :: {-# UNPACK #-} !Text
-- ^ the module in which the log entry was generated
, locpos :: {-# UNPACK #-} !Position
-- ^ the position at which the log entry was generated
}
deriving stock (Eq, Ord, Show, Generic, Lift)
-- | a publish channel with multiple writers
newtype PLogChan = MkPLogChan {unPLogChan :: TChan LogEntry}
deriving newtype (Eq)
-- | a read channel created from a publis
newtype SLogChan = MkSLogChan {unSLogChan :: TChan LogEntry}
deriving newtype (Eq)