{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeSynonymInstances #-}

module Df1.Types
 ( Log(Log, log_time, log_level, log_path, log_message)
 , Level(Debug, Info, Notice, Warning, Error, Critical, Alert, Emergency)
 , Path(Attr, Push), ToPath(path)
 , Segment, unSegment, ToSegment(segment)
 , Key, unKey, ToKey(key)
 , Value, unValue, ToValue(value)
 , Message, unMessage, ToMessage(message)
 ) where

import Control.Exception (SomeException)
import Data.Coerce (coerce)
import qualified Data.Fixed as Fixed
import Data.Foldable (toList)
import Data.Semigroup (Semigroup((<>)))
import Data.Sequence as Seq
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.Int (Int8, Int16, Int32, Int64)
import Data.Word (Word8, Word16, Word32, Word64)
import Numeric.Natural (Natural)
import Data.String (IsString(fromString))
import qualified Data.Time as Time
import qualified Data.Time.Clock.System as Time
import qualified Data.Time.Format.ISO8601 as Time

--------------------------------------------------------------------------------

data Log = Log
  { Log -> SystemTime
log_time :: !Time.SystemTime
    -- ^ First known timestamp when the log was generated.
    --
    -- We use 'Time.SystemTime' rather than 'Time.UTCTime' because it is
    -- cheaper to obtain and to render. You can use
    -- 'Data.Time.Clock.System.systemToUTCTime' to convert it if necessary.
  , Log -> Level
log_level :: !Level
    -- ^ Importance level of the logged message.
  , Log -> Seq Path
log_path :: !(Seq.Seq Path)
    -- ^ 'Path' where the logged message was created from.
    --
    -- The leftmost 'Path' is the closest to the root. The rightmost 'Path' is
    -- the one closest to where the log was generated.
    --
    -- An 'Seq.empty' 'Seq.Seq' is acceptable, conveying the idea of the “root
    -- path”.
  , Log -> Message
log_message :: !Message
    -- ^ Human-readable message itself.
  } deriving (Log -> Log -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Log -> Log -> Bool
$c/= :: Log -> Log -> Bool
== :: Log -> Log -> Bool
$c== :: Log -> Log -> Bool
Eq, Int -> Log -> ShowS
[Log] -> ShowS
Log -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Log] -> ShowS
$cshowList :: [Log] -> ShowS
show :: Log -> String
$cshow :: Log -> String
showsPrec :: Int -> Log -> ShowS
$cshowsPrec :: Int -> Log -> ShowS
Show)

--------------------------------------------------------------------------------

-- | A message text.
--
-- If you have the @OverloadedStrings@ GHC extension enabled, you can build a
-- 'Message' using a string literal:
--
-- @
-- \"foo\" :: 'Message'
-- @
--
-- Otherwise, you can use 'fromString' or 'message'.
--
-- Notice that @\"\" :: 'Message'@ is acceptable, and will be correctly rendered
-- and parsed back.
newtype Message = Message TL.Text
  deriving (Message -> Message -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Message -> Message -> Bool
$c/= :: Message -> Message -> Bool
== :: Message -> Message -> Bool
$c== :: Message -> Message -> Bool
Eq, Int -> Message -> ShowS
[Message] -> ShowS
Message -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Message] -> ShowS
$cshowList :: [Message] -> ShowS
show :: Message -> String
$cshow :: Message -> String
showsPrec :: Int -> Message -> ShowS
$cshowsPrec :: Int -> Message -> ShowS
Show)

unMessage :: Message -> TL.Text
unMessage :: Message -> Text
unMessage = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE unMessage #-}

instance IsString Message where
  fromString :: String -> Message
fromString = forall a. ToMessage a => a -> Message
message
  {-# INLINE fromString #-}

instance Semigroup Message where
  <> :: Message -> Message -> Message
(<>) = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Semigroup a => a -> a -> a
(<>) :: TL.Text -> TL.Text -> TL.Text)
  {-# INLINE (<>) #-}

instance Monoid Message where
  mempty :: Message
mempty = Text -> Message
Message forall a. Monoid a => a
mempty
  {-# INLINE mempty #-}

-- | Convert an arbitrary type to a 'Message'.
--
-- You are encouraged to create custom 'ToMessage' instances for your types
-- making sure you avoid rendering sensitive details such as passwords, so that
-- they don't accidentally end up in logs.
--
-- Any characters that need to be escaped for rendering will be automatically
-- escaped at rendering time. You don't need to escape them here.
class ToMessage a where
  message :: a -> Message

-- | Identity.
instance ToMessage Message where
  message :: Message -> Message
message = forall a. a -> a
id
  {-# INLINE message #-}

-- |
-- @
-- x :: 'TL.Text' == 'unMessage' ('message' x)
-- @
instance ToMessage TL.Text where
  message :: Text -> Message
message = Text -> Message
Message
  {-# INLINE message #-}

-- |
-- @
-- x :: 'T.Text' == 'TL.toStrict' ('unMessage' ('message' x))
-- @
instance ToMessage T.Text where
  message :: Text -> Message
message = Text -> Message
Message forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.fromStrict
  {-# INLINE message #-}

-- |
-- @
-- x :: 'String' == 'TL.unpack' ('unMessage' ('message' x))
-- @
instance ToMessage String where
  message :: String -> Message
message = Text -> Message
Message forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
TL.pack
  {-# INLINE message #-}

instance ToMessage SomeException where
  message :: SomeException -> Message
message = forall a. ToMessage a => a -> Message
message forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE message #-}

--------------------------------------------------------------------------------

-- | Importance of the logged message.
--
-- These levels, listed in increasing order of importance, correspond to the
-- levels used by [syslog(3)](https://linux.die.net/man/3/syslog).
data Level
  = Debug
  -- ^ Message intended to be useful only when deliberately debugging a program.
  | Info
  -- ^ Informational message.
  | Notice
  -- ^ A condition that is not an error, but should possibly be handled
  -- specially.
  | Warning
  -- ^ A warning condition, such as an exception being gracefully handled or
  -- some missing configuration setting being assigned a default value.
  | Error
  -- ^ Error condition, such as an unhandled exception.
  | Critical
  -- ^ Critical condition that could result in system failure, such as a disk
  -- running out of space.
  | Alert
  -- ^ A condition that should be corrected immediately, such as a corrupted
  -- database.
  | Emergency
  -- ^ System is unusable.
  deriving (Level -> Level -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Level -> Level -> Bool
$c/= :: Level -> Level -> Bool
== :: Level -> Level -> Bool
$c== :: Level -> Level -> Bool
Eq, Int -> Level -> ShowS
[Level] -> ShowS
Level -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Level] -> ShowS
$cshowList :: [Level] -> ShowS
show :: Level -> String
$cshow :: Level -> String
showsPrec :: Int -> Level -> ShowS
$cshowsPrec :: Int -> Level -> ShowS
Show, ReadPrec [Level]
ReadPrec Level
Int -> ReadS Level
ReadS [Level]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Level]
$creadListPrec :: ReadPrec [Level]
readPrec :: ReadPrec Level
$creadPrec :: ReadPrec Level
readList :: ReadS [Level]
$creadList :: ReadS [Level]
readsPrec :: Int -> ReadS Level
$creadsPrec :: Int -> ReadS Level
Read, Level
forall a. a -> a -> Bounded a
maxBound :: Level
$cmaxBound :: Level
minBound :: Level
$cminBound :: Level
Bounded, Int -> Level
Level -> Int
Level -> [Level]
Level -> Level
Level -> Level -> [Level]
Level -> Level -> Level -> [Level]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Level -> Level -> Level -> [Level]
$cenumFromThenTo :: Level -> Level -> Level -> [Level]
enumFromTo :: Level -> Level -> [Level]
$cenumFromTo :: Level -> Level -> [Level]
enumFromThen :: Level -> Level -> [Level]
$cenumFromThen :: Level -> Level -> [Level]
enumFrom :: Level -> [Level]
$cenumFrom :: Level -> [Level]
fromEnum :: Level -> Int
$cfromEnum :: Level -> Int
toEnum :: Int -> Level
$ctoEnum :: Int -> Level
pred :: Level -> Level
$cpred :: Level -> Level
succ :: Level -> Level
$csucc :: Level -> Level
Enum)

-- | Order of importance. For example, 'Emergency' is more important than
-- 'Debug':
--
-- @
-- 'Emergency' > 'Debug'  ==  'True'
-- @
deriving instance Ord Level

--------------------------------------------------------------------------------

-- | A path segment.
--
-- If you have the @OverloadedStrings@ GHC extension enabled, you can build a
-- 'Segment' using a string literal:
--
-- @
-- \"foo\" :: 'Segment'
-- @
--
-- Otherwise, you can use 'fromString' or 'segment'.
--
-- Notice that @\"\" :: 'Segment'@ is acceptable, and will be correctly rendered
-- and parsed back.
newtype Segment = Segment TL.Text
  deriving (Segment -> Segment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Segment -> Segment -> Bool
$c/= :: Segment -> Segment -> Bool
== :: Segment -> Segment -> Bool
$c== :: Segment -> Segment -> Bool
Eq, Int -> Segment -> ShowS
[Segment] -> ShowS
Segment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Segment] -> ShowS
$cshowList :: [Segment] -> ShowS
show :: Segment -> String
$cshow :: Segment -> String
showsPrec :: Int -> Segment -> ShowS
$cshowsPrec :: Int -> Segment -> ShowS
Show)

unSegment :: Segment -> TL.Text
unSegment :: Segment -> Text
unSegment = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE unSegment #-}

instance IsString Segment where
  fromString :: String -> Segment
fromString = forall a. ToSegment a => a -> Segment
segment
  {-# INLINE fromString #-}

instance Semigroup Segment where
  <> :: Segment -> Segment -> Segment
(<>) = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Semigroup a => a -> a -> a
(<>) :: TL.Text -> TL.Text -> TL.Text)
  {-# INLINE (<>) #-}

instance Monoid Segment where
  mempty :: Segment
mempty = Text -> Segment
Segment forall a. Monoid a => a
mempty
  {-# INLINE mempty #-}

-- | Convert an arbitrary type to a 'Segment'.
--
-- You are encouraged to create custom 'ToSegment' instances for your types
-- making sure you avoid rendering sensitive details such as passwords, so that
-- they don't accidentally end up in logs.
--
-- Any characters that need to be escaped for rendering will be automatically
-- escaped at rendering time. You don't need to escape them here.
class ToSegment a where
  segment :: a -> Segment

-- | Identity.
instance ToSegment Segment where
  segment :: Segment -> Segment
segment = forall a. a -> a
id
  {-# INLINE segment #-}

-- |
-- @
-- x :: 'TL.Text' == 'unSegment' ('segment' x)
-- @
instance ToSegment TL.Text where
  segment :: Text -> Segment
segment = Text -> Segment
Segment
  {-# INLINE segment #-}

-- |
-- @
-- x :: 'T.Text' == 'TL.toStrict' ('unSegment' ('segment' x))
-- @
instance ToSegment T.Text where
  segment :: Text -> Segment
segment = Text -> Segment
Segment forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.fromStrict
  {-# INLINE segment #-}

-- |
-- @
-- x :: 'String' == 'TL.unpack' ('unSegment' ('segment' x))
-- @
instance ToSegment String where
  segment :: String -> Segment
segment = Text -> Segment
Segment forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
TL.pack
  {-# INLINE segment #-}

instance ToSegment Char where
  segment :: Char -> Segment
segment = Text -> Segment
Segment forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
TL.singleton
  {-# INLINE segment #-}

--------------------------------------------------------------------------------

-- | An attribute key (see 'Attr').
--
-- If you have the @OverloadedStrings@ GHC extension enabled, you can build a
-- 'Key' using a string literal:
--
-- @
-- \"foo\" :: 'Key'
-- @
--
-- Otherwise, you can use 'fromString' or 'key'.
--
-- Notice that @\"\" :: 'Key'@ is acceptable, and will be correctly rendered and
-- parsed back.
newtype Key = Key TL.Text
  deriving (Key -> Key -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Key -> Key -> Bool
$c/= :: Key -> Key -> Bool
== :: Key -> Key -> Bool
$c== :: Key -> Key -> Bool
Eq, Int -> Key -> ShowS
[Key] -> ShowS
Key -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Key] -> ShowS
$cshowList :: [Key] -> ShowS
show :: Key -> String
$cshow :: Key -> String
showsPrec :: Int -> Key -> ShowS
$cshowsPrec :: Int -> Key -> ShowS
Show)

unKey :: Key -> TL.Text
unKey :: Key -> Text
unKey = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE unKey #-}

instance IsString Key where
  fromString :: String -> Key
fromString = forall a. ToKey a => a -> Key
key
  {-# INLINE fromString #-}

instance Semigroup Key where
  <> :: Key -> Key -> Key
(<>) = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Semigroup a => a -> a -> a
(<>) :: TL.Text -> TL.Text -> TL.Text)
  {-# INLINE (<>) #-}

instance Monoid Key where
  mempty :: Key
mempty = Text -> Key
Key forall a. Monoid a => a
mempty
  {-# INLINE mempty #-}

-- | Convert an arbitrary type to a 'Key'.
--
-- You are encouraged to create custom 'ToKey' instances for your types
-- making sure you avoid rendering sensitive details such as passwords, so that
-- they don't accidentally end up in logs.
--
-- Any characters that need to be escaped for rendering will be automatically
-- escaped at rendering time. You don't need to escape them here.
class ToKey a where
  key :: a -> Key

-- | Identity.
instance ToKey Key where
  key :: Key -> Key
key = forall a. a -> a
id
  {-# INLINE key #-}

-- |
-- @
-- x :: 'TL.Text' == 'unKey' ('key' x)
-- @
instance ToKey TL.Text where
  key :: Text -> Key
key = Text -> Key
Key
  {-# INLINE key #-}

-- |
-- @
-- x :: 'T.Text' == 'TL.toStrict' ('unKey' ('key' x))
-- @
instance ToKey T.Text where
  key :: Text -> Key
key = Text -> Key
Key forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.fromStrict
  {-# INLINE key #-}

-- |
-- @
-- x :: 'String' == 'TL.unpack' ('unKey' ('key' x))
-- @
instance ToKey String where
  key :: String -> Key
key = Text -> Key
Key forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
TL.pack
  {-# INLINE key #-}

instance ToKey Char where
  key :: Char -> Key
key = Text -> Key
Key forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
TL.singleton
  {-# INLINE key #-}

--------------------------------------------------------------------------------

-- | An attribute value (see 'Attr').
--
-- If you have the @OverloadedStrings@ GHC extension enabled, you can build a
-- 'Value' using a string literal:
--
-- @
-- \"foo\" :: 'Value'
-- @
--
-- Otherwise, you can use 'fromString' or 'value'.
--
-- Notice that @\"\" :: 'Value'@ is acceptable, and will be correctly rendered
-- and parsed back.
newtype Value = Value TL.Text
  deriving (Value -> Value -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Value -> Value -> Bool
$c/= :: Value -> Value -> Bool
== :: Value -> Value -> Bool
$c== :: Value -> Value -> Bool
Eq, Int -> Value -> ShowS
[Value] -> ShowS
Value -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Value] -> ShowS
$cshowList :: [Value] -> ShowS
show :: Value -> String
$cshow :: Value -> String
showsPrec :: Int -> Value -> ShowS
$cshowsPrec :: Int -> Value -> ShowS
Show)

unValue :: Value -> TL.Text
unValue :: Value -> Text
unValue = coerce :: forall a b. Coercible a b => a -> b
coerce
{-# INLINE unValue #-}

instance IsString Value where
  fromString :: String -> Value
fromString = forall a. ToValue a => a -> Value
value
  {-# INLINE fromString #-}

instance Semigroup Value where
  <> :: Value -> Value -> Value
(<>) = coerce :: forall a b. Coercible a b => a -> b
coerce (forall a. Semigroup a => a -> a -> a
(<>) :: TL.Text -> TL.Text -> TL.Text)
  {-# INLINE (<>) #-}

instance Monoid Value where
  mempty :: Value
mempty = Text -> Value
Value forall a. Monoid a => a
mempty
  {-# INLINE mempty #-}

-- | Convert an arbitrary type to a 'Value'.
--
-- You are encouraged to create custom 'ToValue' instances for your types
-- making sure you avoid rendering sensitive details such as passwords, so that
-- they don't accidentally end up in logs.
--
-- Any characters that need to be escaped for rendering will be automatically
-- escaped at rendering time. You don't need to escape them here.
class ToValue a where
  value :: a -> Value

-- | Identity.
instance ToValue Value where
  value :: Value -> Value
value = forall a. a -> a
id
  {-# INLINE value #-}

-- |
-- @
-- x :: 'TL.Text' == 'unValue' ('value' x)
-- @
instance ToValue TL.Text where
  value :: Text -> Value
value = Text -> Value
Value
  {-# INLINE value #-}

-- |
-- @
-- x :: 'T.Text' == 'TL.toStrict' ('unValue' ('value' x))
-- @
instance ToValue T.Text where
  value :: Text -> Value
value = Text -> Value
Value forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.fromStrict
  {-# INLINE value #-}

-- |
-- @
-- x :: 'String' == 'TL.unpack' ('unValue' ('value' x))
-- @
instance ToValue String where
  value :: String -> Value
value = Text -> Value
Value forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
TL.pack
  {-# INLINE value #-}

instance ToValue SomeException where
  value :: SomeException -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Bool where
  value :: Bool -> Value
value = \Bool
b -> if Bool
b then Value
"true" else Value
"false"
  {-# INLINE value #-}
instance ToValue Char where
  value :: Char -> Value
value = Text -> Value
Value forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
TL.singleton
  {-# INLINE value #-}
instance ToValue Int where
  value :: Int -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Int8 where
  value :: Int8 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Int16 where
  value :: Int16 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Int32 where
  value :: Int32 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Int64 where
  value :: Int64 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Word where
  value :: Word -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Word8 where
  value :: Word8 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Word16 where
  value :: Word16 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Word32 where
  value :: Word32 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Word64 where
  value :: Word64 -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Integer where
  value :: Integer -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Natural where
  value :: Natural -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Float where
  value :: Float -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
instance ToValue Double where
  value :: Double -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
-- | Chops trailing zeros.
instance Fixed.HasResolution a => ToValue (Fixed.Fixed a) where
  value :: Fixed a -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (a :: k). HasResolution a => Bool -> Fixed a -> String
Fixed.showFixed Bool
True
  {-# INLINE value #-}
-- | See 'Time.ISO8601'.
instance ToValue Time.CalendarDiffDays where
  value :: CalendarDiffDays -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ISO8601 t => t -> String
Time.iso8601Show
  {-# INLINE value #-}
-- | See 'Time.ISO8601'.
instance ToValue Time.CalendarDiffTime where
  value :: CalendarDiffTime -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ISO8601 t => t -> String
Time.iso8601Show
  {-# INLINE value #-}
-- | See 'Time.ISO8601'.
instance ToValue Time.Day where
  value :: Day -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ISO8601 t => t -> String
Time.iso8601Show
  {-# INLINE value #-}
-- | See 'Time.ISO8601'.
instance ToValue Time.TimeZone where
  value :: TimeZone -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ISO8601 t => t -> String
Time.iso8601Show
  {-# INLINE value #-}
-- | See 'Time.ISO8601'.
instance ToValue Time.TimeOfDay where
  value :: TimeOfDay -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ISO8601 t => t -> String
Time.iso8601Show
  {-# INLINE value #-}
-- | See 'Time.ISO8601'.
instance ToValue Time.LocalTime where
  value :: LocalTime -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ISO8601 t => t -> String
Time.iso8601Show
  {-# INLINE value #-}
-- | See 'Time.ISO8601'.
instance ToValue Time.ZonedTime where
  value :: ZonedTime -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. ISO8601 t => t -> String
Time.iso8601Show
  {-# INLINE value #-}
-- | @123456s@
instance ToValue Time.NominalDiffTime where
  value :: NominalDiffTime -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
-- | @123456s@
instance ToValue Time.DiffTime where
  value :: DiffTime -> Value
value = forall a. ToValue a => a -> Value
value forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
  {-# INLINE value #-}
-- | Lowercase @monday@, @tuesday@, etc.
instance ToValue Time.DayOfWeek where
   value :: DayOfWeek -> Value
value = \DayOfWeek
x -> case DayOfWeek
x of
     DayOfWeek
Time.Monday    -> Value
"monday"
     DayOfWeek
Time.Tuesday   -> Value
"tuesday"
     DayOfWeek
Time.Wednesday -> Value
"wednesday"
     DayOfWeek
Time.Thursday  -> Value
"thursday"
     DayOfWeek
Time.Friday    -> Value
"friday"
     DayOfWeek
Time.Saturday  -> Value
"saturday"
     DayOfWeek
Time.Sunday    -> Value
"sunday"

--------------------------------------------------------------------------------

-- | 'Path' represents the hierarchical structure of logged messages.
--
-- For example, consider a /df1/ log line as like the following:
--
-- @
-- 1999-12-20T07:11:39.230553031Z \/foo x=a y=b \/bar \/qux z=c z=d WARNING Something
-- @
--
-- For that line, the 'log_path' attribute of the 'Log' datatype will contain
-- the following:
--
-- @
-- [ 'Push' ('segment' \"foo\")
-- , 'Attr' ('key' \"x\") ('value' \"a\")
-- , 'Attr' ('key' \"y\") ('value' \"b\")
-- , 'Push' ('segment' \"bar\")
-- , 'Push' ('segment' \"qux\")
-- , 'Attr' ('key' \"z\") ('value' \"c\")
-- , 'Attr' ('key' \"z\") ('value' \"d\")
-- ] :: 'Seq.Seq' 'Path'
-- @
--
-- Please notice that @[] :: 'Seq.Seq' 'Path'@ is a valid path insofar as /df1/
-- is concerned, and that 'Attr' and 'Push' can be juxtapositioned in any order.
data Path
  = Push !Segment
  | Attr !Key !Value
  deriving (Path -> Path -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Path -> Path -> Bool
$c/= :: Path -> Path -> Bool
== :: Path -> Path -> Bool
$c== :: Path -> Path -> Bool
Eq, Int -> Path -> ShowS
[Path] -> ShowS
Path -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Path] -> ShowS
$cshowList :: [Path] -> ShowS
show :: Path -> String
$cshow :: Path -> String
showsPrec :: Int -> Path -> ShowS
$cshowsPrec :: Int -> Path -> ShowS
Show)

-- | Convert an arbitrary type to a 'Seq'uence of 'Path's.
--
-- You are encouraged to create custom 'ToPath' instances for your types
-- making sure you avoid rendering sensitive details such as passwords, so that
-- they don't accidentally end up in logs.
--
-- Any characters that need to be escaped for rendering will be automatically
-- escaped at rendering time. You don't need to escape them here.
class ToPath a where
  -- | The leftmost 'Path' is the closest to the root. The rightmost 'Path' is
  -- the one closest to where the log was generated.
  --
  -- See the documentation for 'Path'.
  path :: a -> Seq.Seq Path

-- | Identity.
instance ToPath (Seq.Seq Path) where
  path :: Seq Path -> Seq Path
path = forall a. a -> a
id
  {-# INLINE path #-}

-- |
-- @
-- 'path' = 'Seq.fromList' . 'toList'
-- @
instance {-# OVERLAPPABLE #-} Foldable f => ToPath (f Path) where
  path :: f Path -> Seq Path
path = forall a. [a] -> Seq a
Seq.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> [a]
toList
  {-# INLINE path #-}