{-# LANGUAGE UnliftedFFITypes #-}
{-# LANGUAGE MagicHash #-}
{-# OPTIONS_HADDOCK not-home #-}
module Colog.Json.Internal.Structured
(
Structured(..)
, Message(..)
, LogStr(..)
, PushContext(..)
, Severity(..)
, encodeSeverity
, showLS
, ls
, sl
, mkThreadId
) where
import Control.Concurrent
import Data.Aeson
import Data.Aeson.Encoding as Aeson
import Data.Sequence
import Data.String
import Data.String.Conv
import qualified Data.Text as T
import qualified Data.Text.Lazy.Builder as TLB
import Foreign.C
import GHC.Conc
import GHC.Exts hiding (toList)
data Structured
= Segment T.Text
| Attr T.Text Encoding
data Message = Message
{ Message -> Severity
message_severity :: Severity
, Message -> Int
thread_id :: Int
, Message -> Seq Structured
attributes :: Seq Structured
, Message -> LogStr
message :: LogStr
}
newtype LogStr = LogStr TLB.Builder
deriving newtype String -> LogStr
forall a. (String -> a) -> IsString a
fromString :: String -> LogStr
$cfromString :: String -> LogStr
IsString
deriving newtype NonEmpty LogStr -> LogStr
LogStr -> LogStr -> LogStr
forall b. Integral b => b -> LogStr -> LogStr
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> LogStr -> LogStr
$cstimes :: forall b. Integral b => b -> LogStr -> LogStr
sconcat :: NonEmpty LogStr -> LogStr
$csconcat :: NonEmpty LogStr -> LogStr
<> :: LogStr -> LogStr -> LogStr
$c<> :: LogStr -> LogStr -> LogStr
Semigroup
deriving newtype Semigroup LogStr
LogStr
[LogStr] -> LogStr
LogStr -> LogStr -> LogStr
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [LogStr] -> LogStr
$cmconcat :: [LogStr] -> LogStr
mappend :: LogStr -> LogStr -> LogStr
$cmappend :: LogStr -> LogStr -> LogStr
mempty :: LogStr
$cmempty :: LogStr
Monoid
data Severity
= DebugS
| InfoS
| NoticeS
| WarningS
| ErrorS
| CriticalS
| AlertS
| EmergencyS
deriving (Int -> Severity -> ShowS
[Severity] -> ShowS
Severity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Severity] -> ShowS
$cshowList :: [Severity] -> ShowS
show :: Severity -> String
$cshow :: Severity -> String
showsPrec :: Int -> Severity -> ShowS
$cshowsPrec :: Int -> Severity -> ShowS
Show, Severity
forall a. a -> a -> Bounded a
maxBound :: Severity
$cmaxBound :: Severity
minBound :: Severity
$cminBound :: Severity
Bounded, Severity -> Severity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Severity -> Severity -> Bool
$c/= :: Severity -> Severity -> Bool
== :: Severity -> Severity -> Bool
$c== :: Severity -> Severity -> Bool
Eq, Eq Severity
Severity -> Severity -> Bool
Severity -> Severity -> Ordering
Severity -> Severity -> Severity
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Severity -> Severity -> Severity
$cmin :: Severity -> Severity -> Severity
max :: Severity -> Severity -> Severity
$cmax :: Severity -> Severity -> Severity
>= :: Severity -> Severity -> Bool
$c>= :: Severity -> Severity -> Bool
> :: Severity -> Severity -> Bool
$c> :: Severity -> Severity -> Bool
<= :: Severity -> Severity -> Bool
$c<= :: Severity -> Severity -> Bool
< :: Severity -> Severity -> Bool
$c< :: Severity -> Severity -> Bool
compare :: Severity -> Severity -> Ordering
$ccompare :: Severity -> Severity -> Ordering
Ord, Int -> Severity
Severity -> Int
Severity -> [Severity]
Severity -> Severity
Severity -> Severity -> [Severity]
Severity -> Severity -> Severity -> [Severity]
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 :: Severity -> Severity -> Severity -> [Severity]
$cenumFromThenTo :: Severity -> Severity -> Severity -> [Severity]
enumFromTo :: Severity -> Severity -> [Severity]
$cenumFromTo :: Severity -> Severity -> [Severity]
enumFromThen :: Severity -> Severity -> [Severity]
$cenumFromThen :: Severity -> Severity -> [Severity]
enumFrom :: Severity -> [Severity]
$cenumFrom :: Severity -> [Severity]
fromEnum :: Severity -> Int
$cfromEnum :: Severity -> Int
toEnum :: Int -> Severity
$ctoEnum :: Int -> Severity
pred :: Severity -> Severity
$cpred :: Severity -> Severity
succ :: Severity -> Severity
$csucc :: Severity -> Severity
Enum)
encodeSeverity :: Severity -> Aeson.Encoding
{-# INLINE encodeSeverity #-}
encodeSeverity :: Severity -> Encoding
encodeSeverity Severity
DebugS = forall a. Text -> Encoding' a
Aeson.text Text
"DEBUG"
encodeSeverity Severity
InfoS = forall a. Text -> Encoding' a
Aeson.text Text
"INFO"
encodeSeverity Severity
NoticeS = forall a. Text -> Encoding' a
Aeson.text Text
"NOTICE"
encodeSeverity Severity
WarningS = forall a. Text -> Encoding' a
Aeson.text Text
"WARNING"
encodeSeverity Severity
ErrorS = forall a. Text -> Encoding' a
Aeson.text Text
"ERROR"
encodeSeverity Severity
CriticalS = forall a. Text -> Encoding' a
Aeson.text Text
"CRITICAL"
encodeSeverity Severity
AlertS = forall a. Text -> Encoding' a
Aeson.text Text
"ALERT"
encodeSeverity Severity
EmergencyS = forall a. Text -> Encoding' a
Aeson.text Text
"EMERGENCY"
newtype PushContext = PushContext (Seq Structured -> Seq Structured)
sl :: ToJSON a => T.Text -> a -> PushContext
sl :: forall a. ToJSON a => Text -> a -> PushContext
sl Text
label a
msg = (Seq Structured -> Seq Structured) -> PushContext
PushContext \Seq Structured
x ->
Seq Structured
x forall a. Seq a -> a -> Seq a
|> Text -> Encoding -> Structured
Attr Text
label (forall a. ToJSON a => a -> Encoding
toEncoding a
msg)
logStr :: StringConv a T.Text => a -> LogStr
logStr :: forall a. StringConv a Text => a -> LogStr
logStr a
t = Builder -> LogStr
LogStr (Text -> Builder
TLB.fromText forall a b. (a -> b) -> a -> b
$ forall a b. StringConv a b => a -> b
toS a
t)
ls :: StringConv a T.Text => a -> LogStr
ls :: forall a. StringConv a Text => a -> LogStr
ls = forall a. StringConv a Text => a -> LogStr
logStr
showLS :: Show a => a -> LogStr
showLS :: forall a. Show a => a -> LogStr
showLS = forall a. StringConv a Text => a -> LogStr
ls forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
mkThreadId :: ThreadId -> Int
{-# NOINLINE mkThreadId #-}
mkThreadId :: ThreadId -> Int
mkThreadId (ThreadId ThreadId#
tid) = forall a b. (Integral a, Num b) => a -> b
fromIntegral (ThreadId# -> CInt
getThreadId ThreadId#
tid)
foreign import ccall unsafe "rts_getThreadId" getThreadId :: ThreadId# -> CInt