{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
#if MIN_VERSION_base(4, 9, 0)
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
#endif
module Katip.Core where
import Control.Applicative as A
import Control.AutoUpdate
import Control.Concurrent
import qualified Control.Concurrent.Async as Async
import Control.Concurrent.STM
import qualified Control.Concurrent.STM.TBQueue as BQ
import Control.Exception.Safe
import Control.Monad (unless, void, when)
import Control.Monad.Base
#if MIN_VERSION_base(4, 9, 0)
import qualified Control.Monad.Fail as MF
#endif
import Control.Monad.IO.Class
import Control.Monad.IO.Unlift
import Control.Monad.Trans.Class
import Control.Monad.Trans.Control
#if !MIN_VERSION_either(4, 5, 0)
import Control.Monad.Trans.Either
#endif
import Control.Monad.Trans.Except
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Resource (MonadResource, ResourceT,
transResourceT)
import Control.Monad.Trans.RWS.Lazy (RWST, mapRWST)
import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST, mapRWST)
import Control.Monad.Trans.State.Lazy (StateT, mapStateT)
import qualified Control.Monad.Trans.State.Strict as Strict (StateT, mapStateT)
import Control.Monad.Trans.Writer.Lazy (WriterT, mapWriterT)
import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT,
mapWriterT)
import Data.Aeson (FromJSON (..), ToJSON (..),
object)
import qualified Data.Aeson as A
#if MIN_VERSION_aeson(2, 0, 0)
import qualified Data.Aeson.Key as K
import qualified Data.Aeson.KeyMap as KM
import Data.Bifunctor (Bifunctor (..))
#endif
import Data.Foldable as FT
#if !MIN_VERSION_aeson(2, 0, 0)
import qualified Data.HashMap.Strict as HM
#endif
import Data.List
import qualified Data.Map.Strict as M
import Data.Semigroup as SG
import qualified Data.Set as Set
import Data.String
import Data.String.Conv
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as B
import qualified Data.Text.Lazy.Builder.Int as B
import Data.Time
import GHC.Generics hiding (to)
#if MIN_VERSION_base(4, 8, 0)
#if !MIN_VERSION_base(4, 9, 0)
import GHC.SrcLoc
#endif
import GHC.Stack
#endif
import Language.Haskell.TH
import qualified Language.Haskell.TH.Syntax as TH
import Lens.Micro
import Lens.Micro.TH
import Network.HostName
#if mingw32_HOST_OS
import Katip.Compat
#else
import System.Posix
#endif
#if MIN_VERSION_base(4, 19, 0)
import GHC.Conc.Sync (fromThreadId)
#else
import Data.Maybe (fromMaybe)
#endif
readMay :: Read a => String -> Maybe a
readMay :: forall a. Read a => String -> Maybe a
readMay String
s = case [a
x | (a
x,String
t) <- ReadS a
forall a. Read a => ReadS a
reads String
s, (String
"",String
"") <- ReadS String
lex String
t] of
[a
x] -> a -> Maybe a
forall a. a -> Maybe a
Just a
x
[] -> Maybe a
forall a. Maybe a
Nothing
[a]
_ -> Maybe a
forall a. Maybe a
Nothing
{-# INLINE readMay #-}
decimalToText :: Integral a => a -> Text
decimalToText :: forall a. Integral a => a -> Text
decimalToText = LazyText -> Text
TL.toStrict (LazyText -> Text) -> (a -> LazyText) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> LazyText
B.toLazyText (Builder -> LazyText) -> (a -> Builder) -> a -> LazyText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Builder
forall a. Integral a => a -> Builder
B.decimal
newtype Namespace = Namespace { Namespace -> [Text]
unNamespace :: [Text] }
deriving (Namespace -> Namespace -> Bool
(Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool) -> Eq Namespace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Namespace -> Namespace -> Bool
== :: Namespace -> Namespace -> Bool
$c/= :: Namespace -> Namespace -> Bool
/= :: Namespace -> Namespace -> Bool
Eq,Int -> Namespace -> ShowS
[Namespace] -> ShowS
Namespace -> String
(Int -> Namespace -> ShowS)
-> (Namespace -> String)
-> ([Namespace] -> ShowS)
-> Show Namespace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Namespace -> ShowS
showsPrec :: Int -> Namespace -> ShowS
$cshow :: Namespace -> String
show :: Namespace -> String
$cshowList :: [Namespace] -> ShowS
showList :: [Namespace] -> ShowS
Show,ReadPrec [Namespace]
ReadPrec Namespace
Int -> ReadS Namespace
ReadS [Namespace]
(Int -> ReadS Namespace)
-> ReadS [Namespace]
-> ReadPrec Namespace
-> ReadPrec [Namespace]
-> Read Namespace
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Namespace
readsPrec :: Int -> ReadS Namespace
$creadList :: ReadS [Namespace]
readList :: ReadS [Namespace]
$creadPrec :: ReadPrec Namespace
readPrec :: ReadPrec Namespace
$creadListPrec :: ReadPrec [Namespace]
readListPrec :: ReadPrec [Namespace]
Read,Eq Namespace
Eq Namespace =>
(Namespace -> Namespace -> Ordering)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Namespace)
-> (Namespace -> Namespace -> Namespace)
-> Ord Namespace
Namespace -> Namespace -> Bool
Namespace -> Namespace -> Ordering
Namespace -> Namespace -> Namespace
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
$ccompare :: Namespace -> Namespace -> Ordering
compare :: Namespace -> Namespace -> Ordering
$c< :: Namespace -> Namespace -> Bool
< :: Namespace -> Namespace -> Bool
$c<= :: Namespace -> Namespace -> Bool
<= :: Namespace -> Namespace -> Bool
$c> :: Namespace -> Namespace -> Bool
> :: Namespace -> Namespace -> Bool
$c>= :: Namespace -> Namespace -> Bool
>= :: Namespace -> Namespace -> Bool
$cmax :: Namespace -> Namespace -> Namespace
max :: Namespace -> Namespace -> Namespace
$cmin :: Namespace -> Namespace -> Namespace
min :: Namespace -> Namespace -> Namespace
Ord,(forall x. Namespace -> Rep Namespace x)
-> (forall x. Rep Namespace x -> Namespace) -> Generic Namespace
forall x. Rep Namespace x -> Namespace
forall x. Namespace -> Rep Namespace x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Namespace -> Rep Namespace x
from :: forall x. Namespace -> Rep Namespace x
$cto :: forall x. Rep Namespace x -> Namespace
to :: forall x. Rep Namespace x -> Namespace
Generic,[Namespace] -> Value
[Namespace] -> Encoding
Namespace -> Bool
Namespace -> Value
Namespace -> Encoding
(Namespace -> Value)
-> (Namespace -> Encoding)
-> ([Namespace] -> Value)
-> ([Namespace] -> Encoding)
-> (Namespace -> Bool)
-> ToJSON Namespace
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Namespace -> Value
toJSON :: Namespace -> Value
$ctoEncoding :: Namespace -> Encoding
toEncoding :: Namespace -> Encoding
$ctoJSONList :: [Namespace] -> Value
toJSONList :: [Namespace] -> Value
$ctoEncodingList :: [Namespace] -> Encoding
toEncodingList :: [Namespace] -> Encoding
$comitField :: Namespace -> Bool
omitField :: Namespace -> Bool
ToJSON,Maybe Namespace
Value -> Parser [Namespace]
Value -> Parser Namespace
(Value -> Parser Namespace)
-> (Value -> Parser [Namespace])
-> Maybe Namespace
-> FromJSON Namespace
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Namespace
parseJSON :: Value -> Parser Namespace
$cparseJSONList :: Value -> Parser [Namespace]
parseJSONList :: Value -> Parser [Namespace]
$comittedField :: Maybe Namespace
omittedField :: Maybe Namespace
FromJSON,NonEmpty Namespace -> Namespace
Namespace -> Namespace -> Namespace
(Namespace -> Namespace -> Namespace)
-> (NonEmpty Namespace -> Namespace)
-> (forall b. Integral b => b -> Namespace -> Namespace)
-> Semigroup Namespace
forall b. Integral b => b -> Namespace -> Namespace
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: Namespace -> Namespace -> Namespace
<> :: Namespace -> Namespace -> Namespace
$csconcat :: NonEmpty Namespace -> Namespace
sconcat :: NonEmpty Namespace -> Namespace
$cstimes :: forall b. Integral b => b -> Namespace -> Namespace
stimes :: forall b. Integral b => b -> Namespace -> Namespace
SG.Semigroup,Semigroup Namespace
Namespace
Semigroup Namespace =>
Namespace
-> (Namespace -> Namespace -> Namespace)
-> ([Namespace] -> Namespace)
-> Monoid Namespace
[Namespace] -> Namespace
Namespace -> Namespace -> Namespace
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: Namespace
mempty :: Namespace
$cmappend :: Namespace -> Namespace -> Namespace
mappend :: Namespace -> Namespace -> Namespace
$cmconcat :: [Namespace] -> Namespace
mconcat :: [Namespace] -> Namespace
Monoid,(forall (m :: * -> *). Quote m => Namespace -> m Exp)
-> (forall (m :: * -> *). Quote m => Namespace -> Code m Namespace)
-> Lift Namespace
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => Namespace -> m Exp
forall (m :: * -> *). Quote m => Namespace -> Code m Namespace
$clift :: forall (m :: * -> *). Quote m => Namespace -> m Exp
lift :: forall (m :: * -> *). Quote m => Namespace -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => Namespace -> Code m Namespace
liftTyped :: forall (m :: * -> *). Quote m => Namespace -> Code m Namespace
TH.Lift)
instance IsString Namespace where
fromString :: String -> Namespace
fromString String
s = [Text] -> Namespace
Namespace [String -> Text
forall a. IsString a => String -> a
fromString String
s]
intercalateNs :: Namespace -> [Text]
intercalateNs :: Namespace -> [Text]
intercalateNs (Namespace [Text]
xs) = Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
intersperse Text
"." [Text]
xs
{-# INLINE intercalateNs #-}
newtype Environment = Environment { Environment -> Text
getEnvironment :: Text }
deriving (Environment -> Environment -> Bool
(Environment -> Environment -> Bool)
-> (Environment -> Environment -> Bool) -> Eq Environment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Environment -> Environment -> Bool
== :: Environment -> Environment -> Bool
$c/= :: Environment -> Environment -> Bool
/= :: Environment -> Environment -> Bool
Eq,Int -> Environment -> ShowS
[Environment] -> ShowS
Environment -> String
(Int -> Environment -> ShowS)
-> (Environment -> String)
-> ([Environment] -> ShowS)
-> Show Environment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Environment -> ShowS
showsPrec :: Int -> Environment -> ShowS
$cshow :: Environment -> String
show :: Environment -> String
$cshowList :: [Environment] -> ShowS
showList :: [Environment] -> ShowS
Show,ReadPrec [Environment]
ReadPrec Environment
Int -> ReadS Environment
ReadS [Environment]
(Int -> ReadS Environment)
-> ReadS [Environment]
-> ReadPrec Environment
-> ReadPrec [Environment]
-> Read Environment
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Environment
readsPrec :: Int -> ReadS Environment
$creadList :: ReadS [Environment]
readList :: ReadS [Environment]
$creadPrec :: ReadPrec Environment
readPrec :: ReadPrec Environment
$creadListPrec :: ReadPrec [Environment]
readListPrec :: ReadPrec [Environment]
Read,Eq Environment
Eq Environment =>
(Environment -> Environment -> Ordering)
-> (Environment -> Environment -> Bool)
-> (Environment -> Environment -> Bool)
-> (Environment -> Environment -> Bool)
-> (Environment -> Environment -> Bool)
-> (Environment -> Environment -> Environment)
-> (Environment -> Environment -> Environment)
-> Ord Environment
Environment -> Environment -> Bool
Environment -> Environment -> Ordering
Environment -> Environment -> Environment
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
$ccompare :: Environment -> Environment -> Ordering
compare :: Environment -> Environment -> Ordering
$c< :: Environment -> Environment -> Bool
< :: Environment -> Environment -> Bool
$c<= :: Environment -> Environment -> Bool
<= :: Environment -> Environment -> Bool
$c> :: Environment -> Environment -> Bool
> :: Environment -> Environment -> Bool
$c>= :: Environment -> Environment -> Bool
>= :: Environment -> Environment -> Bool
$cmax :: Environment -> Environment -> Environment
max :: Environment -> Environment -> Environment
$cmin :: Environment -> Environment -> Environment
min :: Environment -> Environment -> Environment
Ord,(forall x. Environment -> Rep Environment x)
-> (forall x. Rep Environment x -> Environment)
-> Generic Environment
forall x. Rep Environment x -> Environment
forall x. Environment -> Rep Environment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Environment -> Rep Environment x
from :: forall x. Environment -> Rep Environment x
$cto :: forall x. Rep Environment x -> Environment
to :: forall x. Rep Environment x -> Environment
Generic,[Environment] -> Value
[Environment] -> Encoding
Environment -> Bool
Environment -> Value
Environment -> Encoding
(Environment -> Value)
-> (Environment -> Encoding)
-> ([Environment] -> Value)
-> ([Environment] -> Encoding)
-> (Environment -> Bool)
-> ToJSON Environment
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: Environment -> Value
toJSON :: Environment -> Value
$ctoEncoding :: Environment -> Encoding
toEncoding :: Environment -> Encoding
$ctoJSONList :: [Environment] -> Value
toJSONList :: [Environment] -> Value
$ctoEncodingList :: [Environment] -> Encoding
toEncodingList :: [Environment] -> Encoding
$comitField :: Environment -> Bool
omitField :: Environment -> Bool
ToJSON,Maybe Environment
Value -> Parser [Environment]
Value -> Parser Environment
(Value -> Parser Environment)
-> (Value -> Parser [Environment])
-> Maybe Environment
-> FromJSON Environment
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser Environment
parseJSON :: Value -> Parser Environment
$cparseJSONList :: Value -> Parser [Environment]
parseJSONList :: Value -> Parser [Environment]
$comittedField :: Maybe Environment
omittedField :: Maybe Environment
FromJSON,String -> Environment
(String -> Environment) -> IsString Environment
forall a. (String -> a) -> IsString a
$cfromString :: String -> Environment
fromString :: String -> Environment
IsString)
data Severity
= DebugS
| InfoS
| NoticeS
| WarningS
| ErrorS
| CriticalS
| AlertS
| EmergencyS
deriving (Severity -> Severity -> Bool
(Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool) -> Eq Severity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Severity -> Severity -> Bool
== :: Severity -> Severity -> Bool
$c/= :: Severity -> Severity -> Bool
/= :: Severity -> Severity -> Bool
Eq, Eq Severity
Eq Severity =>
(Severity -> Severity -> Ordering)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool)
-> (Severity -> Severity -> Severity)
-> (Severity -> Severity -> Severity)
-> Ord 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
$ccompare :: Severity -> Severity -> Ordering
compare :: Severity -> Severity -> Ordering
$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
>= :: Severity -> Severity -> Bool
$cmax :: Severity -> Severity -> Severity
max :: Severity -> Severity -> Severity
$cmin :: Severity -> Severity -> Severity
min :: Severity -> Severity -> Severity
Ord, Int -> Severity -> ShowS
[Severity] -> ShowS
Severity -> String
(Int -> Severity -> ShowS)
-> (Severity -> String) -> ([Severity] -> ShowS) -> Show Severity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Severity -> ShowS
showsPrec :: Int -> Severity -> ShowS
$cshow :: Severity -> String
show :: Severity -> String
$cshowList :: [Severity] -> ShowS
showList :: [Severity] -> ShowS
Show, ReadPrec [Severity]
ReadPrec Severity
Int -> ReadS Severity
ReadS [Severity]
(Int -> ReadS Severity)
-> ReadS [Severity]
-> ReadPrec Severity
-> ReadPrec [Severity]
-> Read Severity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Severity
readsPrec :: Int -> ReadS Severity
$creadList :: ReadS [Severity]
readList :: ReadS [Severity]
$creadPrec :: ReadPrec Severity
readPrec :: ReadPrec Severity
$creadListPrec :: ReadPrec [Severity]
readListPrec :: ReadPrec [Severity]
Read, (forall x. Severity -> Rep Severity x)
-> (forall x. Rep Severity x -> Severity) -> Generic Severity
forall x. Rep Severity x -> Severity
forall x. Severity -> Rep Severity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Severity -> Rep Severity x
from :: forall x. Severity -> Rep Severity x
$cto :: forall x. Rep Severity x -> Severity
to :: forall x. Rep Severity x -> Severity
Generic, Int -> Severity
Severity -> Int
Severity -> [Severity]
Severity -> Severity
Severity -> Severity -> [Severity]
Severity -> Severity -> Severity -> [Severity]
(Severity -> Severity)
-> (Severity -> Severity)
-> (Int -> Severity)
-> (Severity -> Int)
-> (Severity -> [Severity])
-> (Severity -> Severity -> [Severity])
-> (Severity -> Severity -> [Severity])
-> (Severity -> Severity -> Severity -> [Severity])
-> Enum 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
$csucc :: Severity -> Severity
succ :: Severity -> Severity
$cpred :: Severity -> Severity
pred :: Severity -> Severity
$ctoEnum :: Int -> Severity
toEnum :: Int -> Severity
$cfromEnum :: Severity -> Int
fromEnum :: Severity -> Int
$cenumFrom :: Severity -> [Severity]
enumFrom :: Severity -> [Severity]
$cenumFromThen :: Severity -> Severity -> [Severity]
enumFromThen :: Severity -> Severity -> [Severity]
$cenumFromTo :: Severity -> Severity -> [Severity]
enumFromTo :: Severity -> Severity -> [Severity]
$cenumFromThenTo :: Severity -> Severity -> Severity -> [Severity]
enumFromThenTo :: Severity -> Severity -> Severity -> [Severity]
Enum, Severity
Severity -> Severity -> Bounded Severity
forall a. a -> a -> Bounded a
$cminBound :: Severity
minBound :: Severity
$cmaxBound :: Severity
maxBound :: Severity
Bounded, (forall (m :: * -> *). Quote m => Severity -> m Exp)
-> (forall (m :: * -> *). Quote m => Severity -> Code m Severity)
-> Lift Severity
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => Severity -> m Exp
forall (m :: * -> *). Quote m => Severity -> Code m Severity
$clift :: forall (m :: * -> *). Quote m => Severity -> m Exp
lift :: forall (m :: * -> *). Quote m => Severity -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => Severity -> Code m Severity
liftTyped :: forall (m :: * -> *). Quote m => Severity -> Code m Severity
TH.Lift)
data Verbosity = V0 | V1 | V2 | V3
deriving (Verbosity -> Verbosity -> Bool
(Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool) -> Eq Verbosity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Verbosity -> Verbosity -> Bool
== :: Verbosity -> Verbosity -> Bool
$c/= :: Verbosity -> Verbosity -> Bool
/= :: Verbosity -> Verbosity -> Bool
Eq, Eq Verbosity
Eq Verbosity =>
(Verbosity -> Verbosity -> Ordering)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Verbosity)
-> (Verbosity -> Verbosity -> Verbosity)
-> Ord Verbosity
Verbosity -> Verbosity -> Bool
Verbosity -> Verbosity -> Ordering
Verbosity -> Verbosity -> Verbosity
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
$ccompare :: Verbosity -> Verbosity -> Ordering
compare :: Verbosity -> Verbosity -> Ordering
$c< :: Verbosity -> Verbosity -> Bool
< :: Verbosity -> Verbosity -> Bool
$c<= :: Verbosity -> Verbosity -> Bool
<= :: Verbosity -> Verbosity -> Bool
$c> :: Verbosity -> Verbosity -> Bool
> :: Verbosity -> Verbosity -> Bool
$c>= :: Verbosity -> Verbosity -> Bool
>= :: Verbosity -> Verbosity -> Bool
$cmax :: Verbosity -> Verbosity -> Verbosity
max :: Verbosity -> Verbosity -> Verbosity
$cmin :: Verbosity -> Verbosity -> Verbosity
min :: Verbosity -> Verbosity -> Verbosity
Ord, Int -> Verbosity -> ShowS
[Verbosity] -> ShowS
Verbosity -> String
(Int -> Verbosity -> ShowS)
-> (Verbosity -> String)
-> ([Verbosity] -> ShowS)
-> Show Verbosity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Verbosity -> ShowS
showsPrec :: Int -> Verbosity -> ShowS
$cshow :: Verbosity -> String
show :: Verbosity -> String
$cshowList :: [Verbosity] -> ShowS
showList :: [Verbosity] -> ShowS
Show, ReadPrec [Verbosity]
ReadPrec Verbosity
Int -> ReadS Verbosity
ReadS [Verbosity]
(Int -> ReadS Verbosity)
-> ReadS [Verbosity]
-> ReadPrec Verbosity
-> ReadPrec [Verbosity]
-> Read Verbosity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Verbosity
readsPrec :: Int -> ReadS Verbosity
$creadList :: ReadS [Verbosity]
readList :: ReadS [Verbosity]
$creadPrec :: ReadPrec Verbosity
readPrec :: ReadPrec Verbosity
$creadListPrec :: ReadPrec [Verbosity]
readListPrec :: ReadPrec [Verbosity]
Read, (forall x. Verbosity -> Rep Verbosity x)
-> (forall x. Rep Verbosity x -> Verbosity) -> Generic Verbosity
forall x. Rep Verbosity x -> Verbosity
forall x. Verbosity -> Rep Verbosity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Verbosity -> Rep Verbosity x
from :: forall x. Verbosity -> Rep Verbosity x
$cto :: forall x. Rep Verbosity x -> Verbosity
to :: forall x. Rep Verbosity x -> Verbosity
Generic, Int -> Verbosity
Verbosity -> Int
Verbosity -> [Verbosity]
Verbosity -> Verbosity
Verbosity -> Verbosity -> [Verbosity]
Verbosity -> Verbosity -> Verbosity -> [Verbosity]
(Verbosity -> Verbosity)
-> (Verbosity -> Verbosity)
-> (Int -> Verbosity)
-> (Verbosity -> Int)
-> (Verbosity -> [Verbosity])
-> (Verbosity -> Verbosity -> [Verbosity])
-> (Verbosity -> Verbosity -> [Verbosity])
-> (Verbosity -> Verbosity -> Verbosity -> [Verbosity])
-> Enum Verbosity
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Verbosity -> Verbosity
succ :: Verbosity -> Verbosity
$cpred :: Verbosity -> Verbosity
pred :: Verbosity -> Verbosity
$ctoEnum :: Int -> Verbosity
toEnum :: Int -> Verbosity
$cfromEnum :: Verbosity -> Int
fromEnum :: Verbosity -> Int
$cenumFrom :: Verbosity -> [Verbosity]
enumFrom :: Verbosity -> [Verbosity]
$cenumFromThen :: Verbosity -> Verbosity -> [Verbosity]
enumFromThen :: Verbosity -> Verbosity -> [Verbosity]
$cenumFromTo :: Verbosity -> Verbosity -> [Verbosity]
enumFromTo :: Verbosity -> Verbosity -> [Verbosity]
$cenumFromThenTo :: Verbosity -> Verbosity -> Verbosity -> [Verbosity]
enumFromThenTo :: Verbosity -> Verbosity -> Verbosity -> [Verbosity]
Enum, Verbosity
Verbosity -> Verbosity -> Bounded Verbosity
forall a. a -> a -> Bounded a
$cminBound :: Verbosity
minBound :: Verbosity
$cmaxBound :: Verbosity
maxBound :: Verbosity
Bounded, (forall (m :: * -> *). Quote m => Verbosity -> m Exp)
-> (forall (m :: * -> *). Quote m => Verbosity -> Code m Verbosity)
-> Lift Verbosity
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => Verbosity -> m Exp
forall (m :: * -> *). Quote m => Verbosity -> Code m Verbosity
$clift :: forall (m :: * -> *). Quote m => Verbosity -> m Exp
lift :: forall (m :: * -> *). Quote m => Verbosity -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => Verbosity -> Code m Verbosity
liftTyped :: forall (m :: * -> *). Quote m => Verbosity -> Code m Verbosity
TH.Lift)
{-# INLINE renderSeverity #-}
renderSeverity :: Severity -> Text
renderSeverity :: Severity -> Text
renderSeverity !Severity
s = case Severity
s of
Severity
DebugS -> Text
"Debug"
Severity
InfoS -> Text
"Info"
Severity
NoticeS -> Text
"Notice"
Severity
WarningS -> Text
"Warning"
Severity
ErrorS -> Text
"Error"
Severity
CriticalS -> Text
"Critical"
Severity
AlertS -> Text
"Alert"
Severity
EmergencyS -> Text
"Emergency"
{-# INLINE textToSeverity #-}
textToSeverity :: Text -> Maybe Severity
textToSeverity :: Text -> Maybe Severity
textToSeverity = Text -> Maybe Severity
forall {a}. (Eq a, IsString a) => a -> Maybe Severity
go (Text -> Maybe Severity)
-> (Text -> Text) -> Text -> Maybe Severity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower
where
go :: a -> Maybe Severity
go a
"debug" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
DebugS
go a
"info" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
InfoS
go a
"notice" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
NoticeS
go a
"warning" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
WarningS
go a
"error" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
ErrorS
go a
"critical" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
CriticalS
go a
"alert" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
AlertS
go a
"emergency" = Severity -> Maybe Severity
forall a. a -> Maybe a
Just Severity
EmergencyS
go a
_ = Maybe Severity
forall a. Maybe a
Nothing
instance ToJSON Severity where
toJSON :: Severity -> Value
toJSON Severity
s = Text -> Value
A.String (Severity -> Text
renderSeverity Severity
s)
instance FromJSON Severity where
parseJSON :: Value -> Parser Severity
parseJSON = String -> (Text -> Parser Severity) -> Value -> Parser Severity
forall a. String -> (Text -> Parser a) -> Value -> Parser a
A.withText String
"Severity" Text -> Parser Severity
forall {m :: * -> *}. MonadFail m => Text -> m Severity
parseSeverity
where
parseSeverity :: Text -> m Severity
parseSeverity Text
t = case Text -> Maybe Severity
textToSeverity Text
t of
Just Severity
x -> Severity -> m Severity
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Severity
x
Maybe Severity
Nothing -> String -> m Severity
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m Severity) -> String -> m Severity
forall a b. (a -> b) -> a -> b
$ String
"Invalid Severity " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a b. StringConv a b => a -> b
toS Text
t
instance ToJSON Verbosity where
toJSON :: Verbosity -> Value
toJSON Verbosity
s = Text -> Value
A.String (Text -> Value) -> Text -> Value
forall a b. (a -> b) -> a -> b
$ case Verbosity
s of
Verbosity
V0 -> Text
"V0"
Verbosity
V1 -> Text
"V1"
Verbosity
V2 -> Text
"V2"
Verbosity
V3 -> Text
"V3"
instance FromJSON Verbosity where
parseJSON :: Value -> Parser Verbosity
parseJSON = String -> (Text -> Parser Verbosity) -> Value -> Parser Verbosity
forall a. String -> (Text -> Parser a) -> Value -> Parser a
A.withText String
"Verbosity" ((Text -> Parser Verbosity) -> Value -> Parser Verbosity)
-> (Text -> Parser Verbosity) -> Value -> Parser Verbosity
forall a b. (a -> b) -> a -> b
$ \Text
s -> case Text
s of
Text
"V0" -> Verbosity -> Parser Verbosity
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity
V0
Text
"V1" -> Verbosity -> Parser Verbosity
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity
V1
Text
"V2" -> Verbosity -> Parser Verbosity
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity
V2
Text
"V3" -> Verbosity -> Parser Verbosity
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Verbosity
V3
Text
_ -> String -> Parser Verbosity
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Verbosity) -> String -> Parser Verbosity
forall a b. (a -> b) -> a -> b
$ String
"Invalid Verbosity " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a b. StringConv a b => a -> b
toS Text
s
newtype LogStr = LogStr { LogStr -> Builder
unLogStr :: B.Builder }
deriving ((forall x. LogStr -> Rep LogStr x)
-> (forall x. Rep LogStr x -> LogStr) -> Generic LogStr
forall x. Rep LogStr x -> LogStr
forall x. LogStr -> Rep LogStr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LogStr -> Rep LogStr x
from :: forall x. LogStr -> Rep LogStr x
$cto :: forall x. Rep LogStr x -> LogStr
to :: forall x. Rep LogStr x -> LogStr
Generic, Int -> LogStr -> ShowS
[LogStr] -> ShowS
LogStr -> String
(Int -> LogStr -> ShowS)
-> (LogStr -> String) -> ([LogStr] -> ShowS) -> Show LogStr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LogStr -> ShowS
showsPrec :: Int -> LogStr -> ShowS
$cshow :: LogStr -> String
show :: LogStr -> String
$cshowList :: [LogStr] -> ShowS
showList :: [LogStr] -> ShowS
Show, LogStr -> LogStr -> Bool
(LogStr -> LogStr -> Bool)
-> (LogStr -> LogStr -> Bool) -> Eq LogStr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LogStr -> LogStr -> Bool
== :: LogStr -> LogStr -> Bool
$c/= :: LogStr -> LogStr -> Bool
/= :: LogStr -> LogStr -> Bool
Eq)
instance IsString LogStr where
fromString :: String -> LogStr
fromString = Builder -> LogStr
LogStr (Builder -> LogStr) -> (String -> Builder) -> String -> LogStr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Builder
B.fromString
instance Semigroup LogStr where
(LogStr Builder
a) <> :: LogStr -> LogStr -> LogStr
<> (LogStr Builder
b) = Builder -> LogStr
LogStr (Builder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
b)
{-# INLINE (<>) #-}
instance Monoid LogStr where
mappend :: LogStr -> LogStr -> LogStr
mappend = LogStr -> LogStr -> LogStr
forall a. Semigroup a => a -> a -> a
(<>)
mempty :: LogStr
mempty = Builder -> LogStr
LogStr Builder
forall a. Monoid a => a
mempty
{-# INLINE mempty #-}
instance FromJSON LogStr where
parseJSON :: Value -> Parser LogStr
parseJSON = String -> (Text -> Parser LogStr) -> Value -> Parser LogStr
forall a. String -> (Text -> Parser a) -> Value -> Parser a
A.withText String
"LogStr" Text -> Parser LogStr
parseLogStr
where
parseLogStr :: Text -> Parser LogStr
parseLogStr = LogStr -> Parser LogStr
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (LogStr -> Parser LogStr)
-> (Text -> LogStr) -> Text -> Parser LogStr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> LogStr
LogStr (Builder -> LogStr) -> (Text -> Builder) -> Text -> LogStr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Builder
B.fromText
logStr :: StringConv a Text => a -> LogStr
logStr :: forall a. StringConv a Text => a -> LogStr
logStr a
t = Builder -> LogStr
LogStr (Text -> Builder
B.fromText (Text -> Builder) -> Text -> Builder
forall a b. (a -> b) -> a -> b
$ a -> Text
forall a b. StringConv a b => a -> b
toS a
t)
{-# INLINE logStr #-}
ls :: StringConv a Text => a -> LogStr
ls :: forall a. StringConv a Text => a -> LogStr
ls = a -> LogStr
forall a. StringConv a Text => a -> LogStr
logStr
{-# INLINE ls #-}
showLS :: Show a => a -> LogStr
showLS :: forall a. Show a => a -> LogStr
showLS = String -> LogStr
forall a. StringConv a Text => a -> LogStr
ls (String -> LogStr) -> (a -> String) -> a -> LogStr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Show a => a -> String
show
{-# INLINE showLS #-}
newtype ThreadIdText = ThreadIdText {
ThreadIdText -> Text
getThreadIdText :: Text
} deriving ([ThreadIdText] -> Value
[ThreadIdText] -> Encoding
ThreadIdText -> Bool
ThreadIdText -> Value
ThreadIdText -> Encoding
(ThreadIdText -> Value)
-> (ThreadIdText -> Encoding)
-> ([ThreadIdText] -> Value)
-> ([ThreadIdText] -> Encoding)
-> (ThreadIdText -> Bool)
-> ToJSON ThreadIdText
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> (a -> Bool)
-> ToJSON a
$ctoJSON :: ThreadIdText -> Value
toJSON :: ThreadIdText -> Value
$ctoEncoding :: ThreadIdText -> Encoding
toEncoding :: ThreadIdText -> Encoding
$ctoJSONList :: [ThreadIdText] -> Value
toJSONList :: [ThreadIdText] -> Value
$ctoEncodingList :: [ThreadIdText] -> Encoding
toEncodingList :: [ThreadIdText] -> Encoding
$comitField :: ThreadIdText -> Bool
omitField :: ThreadIdText -> Bool
ToJSON, Maybe ThreadIdText
Value -> Parser [ThreadIdText]
Value -> Parser ThreadIdText
(Value -> Parser ThreadIdText)
-> (Value -> Parser [ThreadIdText])
-> Maybe ThreadIdText
-> FromJSON ThreadIdText
forall a.
(Value -> Parser a)
-> (Value -> Parser [a]) -> Maybe a -> FromJSON a
$cparseJSON :: Value -> Parser ThreadIdText
parseJSON :: Value -> Parser ThreadIdText
$cparseJSONList :: Value -> Parser [ThreadIdText]
parseJSONList :: Value -> Parser [ThreadIdText]
$comittedField :: Maybe ThreadIdText
omittedField :: Maybe ThreadIdText
FromJSON, Int -> ThreadIdText -> ShowS
[ThreadIdText] -> ShowS
ThreadIdText -> String
(Int -> ThreadIdText -> ShowS)
-> (ThreadIdText -> String)
-> ([ThreadIdText] -> ShowS)
-> Show ThreadIdText
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ThreadIdText -> ShowS
showsPrec :: Int -> ThreadIdText -> ShowS
$cshow :: ThreadIdText -> String
show :: ThreadIdText -> String
$cshowList :: [ThreadIdText] -> ShowS
showList :: [ThreadIdText] -> ShowS
Show, ThreadIdText -> ThreadIdText -> Bool
(ThreadIdText -> ThreadIdText -> Bool)
-> (ThreadIdText -> ThreadIdText -> Bool) -> Eq ThreadIdText
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ThreadIdText -> ThreadIdText -> Bool
== :: ThreadIdText -> ThreadIdText -> Bool
$c/= :: ThreadIdText -> ThreadIdText -> Bool
/= :: ThreadIdText -> ThreadIdText -> Bool
Eq, Eq ThreadIdText
Eq ThreadIdText =>
(ThreadIdText -> ThreadIdText -> Ordering)
-> (ThreadIdText -> ThreadIdText -> Bool)
-> (ThreadIdText -> ThreadIdText -> Bool)
-> (ThreadIdText -> ThreadIdText -> Bool)
-> (ThreadIdText -> ThreadIdText -> Bool)
-> (ThreadIdText -> ThreadIdText -> ThreadIdText)
-> (ThreadIdText -> ThreadIdText -> ThreadIdText)
-> Ord ThreadIdText
ThreadIdText -> ThreadIdText -> Bool
ThreadIdText -> ThreadIdText -> Ordering
ThreadIdText -> ThreadIdText -> ThreadIdText
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
$ccompare :: ThreadIdText -> ThreadIdText -> Ordering
compare :: ThreadIdText -> ThreadIdText -> Ordering
$c< :: ThreadIdText -> ThreadIdText -> Bool
< :: ThreadIdText -> ThreadIdText -> Bool
$c<= :: ThreadIdText -> ThreadIdText -> Bool
<= :: ThreadIdText -> ThreadIdText -> Bool
$c> :: ThreadIdText -> ThreadIdText -> Bool
> :: ThreadIdText -> ThreadIdText -> Bool
$c>= :: ThreadIdText -> ThreadIdText -> Bool
>= :: ThreadIdText -> ThreadIdText -> Bool
$cmax :: ThreadIdText -> ThreadIdText -> ThreadIdText
max :: ThreadIdText -> ThreadIdText -> ThreadIdText
$cmin :: ThreadIdText -> ThreadIdText -> ThreadIdText
min :: ThreadIdText -> ThreadIdText -> ThreadIdText
Ord)
mkThreadIdText :: ThreadId -> ThreadIdText
#if MIN_VERSION_base(4, 19, 0)
mkThreadIdText = ThreadIdText . decimalToText . fromThreadId
#else
mkThreadIdText :: ThreadId -> ThreadIdText
mkThreadIdText = Text -> ThreadIdText
ThreadIdText (Text -> ThreadIdText)
-> (ThreadId -> Text) -> ThreadId -> ThreadIdText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text
stripPrefix' Text
"ThreadId " (Text -> Text) -> (ThreadId -> Text) -> ThreadId -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> (ThreadId -> String) -> ThreadId -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThreadId -> String
forall a. Show a => a -> String
show
where
stripPrefix' :: Text -> Text -> Text
stripPrefix' Text
pfx Text
t = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
t (Text -> Text -> Maybe Text
T.stripPrefix Text
pfx Text
t)
#endif
{-# INLINE mkThreadIdText #-}
data Item a = Item {
forall a. Item a -> Namespace
_itemApp :: Namespace
, forall a. Item a -> Environment
_itemEnv :: Environment
, forall a. Item a -> Severity
_itemSeverity :: {-# UNPACK #-} !Severity
, forall a. Item a -> ThreadIdText
_itemThread :: ThreadIdText
, forall a. Item a -> String
_itemHost :: HostName
, forall a. Item a -> ProcessID
_itemProcess :: ProcessID
, forall a. Item a -> a
_itemPayload :: a
, forall a. Item a -> LogStr
_itemMessage :: LogStr
, forall a. Item a -> UTCTime
_itemTime :: UTCTime
, forall a. Item a -> Namespace
_itemNamespace :: Namespace
, forall a. Item a -> Maybe Loc
_itemLoc :: Maybe Loc
} deriving ((forall x. Item a -> Rep (Item a) x)
-> (forall x. Rep (Item a) x -> Item a) -> Generic (Item a)
forall x. Rep (Item a) x -> Item a
forall x. Item a -> Rep (Item a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Item a) x -> Item a
forall a x. Item a -> Rep (Item a) x
$cfrom :: forall a x. Item a -> Rep (Item a) x
from :: forall x. Item a -> Rep (Item a) x
$cto :: forall a x. Rep (Item a) x -> Item a
to :: forall x. Rep (Item a) x -> Item a
Generic, (forall a b. (a -> b) -> Item a -> Item b)
-> (forall a b. a -> Item b -> Item a) -> Functor Item
forall a b. a -> Item b -> Item a
forall a b. (a -> b) -> Item a -> Item b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Item a -> Item b
fmap :: forall a b. (a -> b) -> Item a -> Item b
$c<$ :: forall a b. a -> Item b -> Item a
<$ :: forall a b. a -> Item b -> Item a
Functor)
makeLenses ''Item
instance Eq a => Eq (Item a) where
Item a
a == :: Item a -> Item a -> Bool
== Item a
b = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
FT.and [ Item a -> Namespace
forall a. Item a -> Namespace
_itemApp Item a
a Namespace -> Namespace -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> Namespace
forall a. Item a -> Namespace
_itemApp Item a
b
, Item a -> Environment
forall a. Item a -> Environment
_itemEnv Item a
a Environment -> Environment -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> Environment
forall a. Item a -> Environment
_itemEnv Item a
b
, Item a -> Severity
forall a. Item a -> Severity
_itemSeverity Item a
a Severity -> Severity -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> Severity
forall a. Item a -> Severity
_itemSeverity Item a
b
, Item a -> ThreadIdText
forall a. Item a -> ThreadIdText
_itemThread Item a
a ThreadIdText -> ThreadIdText -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> ThreadIdText
forall a. Item a -> ThreadIdText
_itemThread Item a
b
, Item a -> String
forall a. Item a -> String
_itemHost Item a
a String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> String
forall a. Item a -> String
_itemHost Item a
b
, Item a -> ProcessID
forall a. Item a -> ProcessID
_itemProcess Item a
a ProcessID -> ProcessID -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> ProcessID
forall a. Item a -> ProcessID
_itemProcess Item a
b
, Item a -> a
forall a. Item a -> a
_itemPayload Item a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> a
forall a. Item a -> a
_itemPayload Item a
b
, Item a -> LogStr
forall a. Item a -> LogStr
_itemMessage Item a
a LogStr -> LogStr -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> LogStr
forall a. Item a -> LogStr
_itemMessage Item a
b
, Item a -> UTCTime
forall a. Item a -> UTCTime
_itemTime Item a
a UTCTime -> UTCTime -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> UTCTime
forall a. Item a -> UTCTime
_itemTime Item a
b
, Item a -> Namespace
forall a. Item a -> Namespace
_itemNamespace Item a
a Namespace -> Namespace -> Bool
forall a. Eq a => a -> a -> Bool
== Item a -> Namespace
forall a. Item a -> Namespace
_itemNamespace Item a
b
, case (Item a -> Maybe Loc
forall a. Item a -> Maybe Loc
_itemLoc Item a
a, Item a -> Maybe Loc
forall a. Item a -> Maybe Loc
_itemLoc Item a
b) of
(Maybe Loc
Nothing, Maybe Loc
Nothing) -> Bool
True
(Just Loc
l1, Just Loc
l2) -> [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
FT.and [ Loc -> String
loc_filename Loc
l1 String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== Loc -> String
loc_filename Loc
l2
, Loc -> String
loc_package Loc
l1 String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== Loc -> String
loc_package Loc
l2
, Loc -> String
loc_module Loc
l1 String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== Loc -> String
loc_module Loc
l2
, Loc -> CharPos
loc_start Loc
l1 CharPos -> CharPos -> Bool
forall a. Eq a => a -> a -> Bool
== Loc -> CharPos
loc_start Loc
l2
, Loc -> CharPos
loc_end Loc
l1 CharPos -> CharPos -> Bool
forall a. Eq a => a -> a -> Bool
== Loc -> CharPos
loc_end Loc
l2
]
(Maybe Loc, Maybe Loc)
_ -> Bool
False
]
instance Show a => Show (Item a) where
showsPrec :: Int -> Item a -> ShowS
showsPrec Int
d Item{a
String
Maybe Loc
UTCTime
ProcessID
ThreadIdText
LogStr
Severity
Environment
Namespace
_itemApp :: forall a. Item a -> Namespace
_itemEnv :: forall a. Item a -> Environment
_itemSeverity :: forall a. Item a -> Severity
_itemThread :: forall a. Item a -> ThreadIdText
_itemHost :: forall a. Item a -> String
_itemProcess :: forall a. Item a -> ProcessID
_itemPayload :: forall a. Item a -> a
_itemMessage :: forall a. Item a -> LogStr
_itemTime :: forall a. Item a -> UTCTime
_itemNamespace :: forall a. Item a -> Namespace
_itemLoc :: forall a. Item a -> Maybe Loc
_itemApp :: Namespace
_itemEnv :: Environment
_itemSeverity :: Severity
_itemThread :: ThreadIdText
_itemHost :: String
_itemProcess :: ProcessID
_itemPayload :: a
_itemMessage :: LogStr
_itemTime :: UTCTime
_itemNamespace :: Namespace
_itemLoc :: Maybe Loc
..} = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11) ( String -> ShowS
showString String
"Item {"
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Namespace -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemApp" Namespace
_itemApp
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Environment -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemEnv" Environment
_itemEnv
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Severity -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemSeverity" Severity
_itemSeverity
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ThreadIdText -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemThread" ThreadIdText
_itemThread
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemHost" String
_itemHost
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ProcessID -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemProcess" ProcessID
_itemProcess
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> a -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemPayload" a
_itemPayload
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> LogStr -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemMessage" LogStr
_itemMessage
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> UTCTime -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemTime" UTCTime
_itemTime
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Namespace -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"_itemNamespace" Namespace
_itemNamespace
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"_itemLoc = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe LocShow -> ShowS
forall a. Show a => a -> ShowS
shows (Loc -> LocShow
LocShow (Loc -> LocShow) -> Maybe Loc -> Maybe LocShow
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Loc
_itemLoc)
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'
)
where
field :: String -> a -> ShowS
field String
n a
v = String -> ShowS
showString String
n ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ShowS
forall a. Show a => a -> ShowS
shows a
v ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
", "
newtype LocShow = LocShow Loc
instance Show LocShow where
showsPrec :: Int -> LocShow -> ShowS
showsPrec Int
d (LocShow Loc{String
CharPos
loc_filename :: Loc -> String
loc_package :: Loc -> String
loc_module :: Loc -> String
loc_start :: Loc -> CharPos
loc_end :: Loc -> CharPos
loc_filename :: String
loc_package :: String
loc_module :: String
loc_start :: CharPos
loc_end :: CharPos
..}) = Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
11) ( String -> ShowS
showString String
"Loc {"
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"loc_filename" String
loc_filename
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"loc_package" String
loc_package
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"loc_module" String
loc_module
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> CharPos -> ShowS
forall {a}. Show a => String -> a -> ShowS
field String
"loc_start" CharPos
loc_start
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
"loc_end = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CharPos -> ShowS
forall a. Show a => a -> ShowS
shows CharPos
loc_end
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> ShowS
showChar Char
'}'
)
where
field :: String -> a -> ShowS
field String
n a
v = String -> ShowS
showString String
n ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ShowS
forall a. Show a => a -> ShowS
shows a
v ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
", "
instance ToJSON a => ToJSON (Item a) where
toJSON :: Item a -> Value
toJSON Item{a
String
Maybe Loc
UTCTime
ProcessID
ThreadIdText
LogStr
Severity
Environment
Namespace
_itemApp :: forall a. Item a -> Namespace
_itemEnv :: forall a. Item a -> Environment
_itemSeverity :: forall a. Item a -> Severity
_itemThread :: forall a. Item a -> ThreadIdText
_itemHost :: forall a. Item a -> String
_itemProcess :: forall a. Item a -> ProcessID
_itemPayload :: forall a. Item a -> a
_itemMessage :: forall a. Item a -> LogStr
_itemTime :: forall a. Item a -> UTCTime
_itemNamespace :: forall a. Item a -> Namespace
_itemLoc :: forall a. Item a -> Maybe Loc
_itemApp :: Namespace
_itemEnv :: Environment
_itemSeverity :: Severity
_itemThread :: ThreadIdText
_itemHost :: String
_itemProcess :: ProcessID
_itemPayload :: a
_itemMessage :: LogStr
_itemTime :: UTCTime
_itemNamespace :: Namespace
_itemLoc :: Maybe Loc
..} = [Pair] -> Value
A.object
[ Key
"app" Key -> Namespace -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= Namespace
_itemApp
, Key
"env" Key -> Environment -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= Environment
_itemEnv
, Key
"sev" Key -> Severity -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= Severity
_itemSeverity
, Key
"thread" Key -> Text -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= ThreadIdText -> Text
getThreadIdText ThreadIdText
_itemThread
, Key
"host" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= String
_itemHost
, Key
"pid" Key -> ProcessIDJs -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= ProcessID -> ProcessIDJs
ProcessIDJs ProcessID
_itemProcess
, Key
"data" Key -> a -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= a
_itemPayload
, Key
"msg" Key -> LazyText -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= (Builder -> LazyText
B.toLazyText (Builder -> LazyText) -> Builder -> LazyText
forall a b. (a -> b) -> a -> b
$ LogStr -> Builder
unLogStr LogStr
_itemMessage)
, Key
"at" Key -> UTCTime -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= UTCTime
_itemTime
, Key
"ns" Key -> Namespace -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= Namespace
_itemNamespace
, Key
"loc" Key -> Maybe LocJs -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= (Loc -> LocJs) -> Maybe Loc -> Maybe LocJs
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Loc -> LocJs
LocJs Maybe Loc
_itemLoc
]
newtype LocJs = LocJs { LocJs -> Loc
getLocJs :: Loc }
instance ToJSON LocJs where
toJSON :: LocJs -> Value
toJSON (LocJs (Loc String
fn String
p String
m (Int
l, Int
c) CharPos
_)) = [Pair] -> Value
A.object
[ Key
"loc_fn" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= String
fn
, Key
"loc_pkg" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= String
p
, Key
"loc_mod" Key -> String -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= String
m
, Key
"loc_ln" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= Int
l
, Key
"loc_col" Key -> Int -> Pair
forall v. ToJSON v => Key -> v -> Pair
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= Int
c
]
instance FromJSON LocJs where
parseJSON :: Value -> Parser LocJs
parseJSON = String -> (Object -> Parser LocJs) -> Value -> Parser LocJs
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LocJs" Object -> Parser LocJs
parseLocJs
where
parseLocJs :: Object -> Parser LocJs
parseLocJs Object
o = do
String
fn <- Object
o Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"loc_fn"
String
p <- Object
o Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"loc_pkg"
String
m <- Object
o Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"loc_mod"
Int
l <- Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"loc_ln"
Int
c <- Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"loc_col"
LocJs -> Parser LocJs
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (LocJs -> Parser LocJs) -> LocJs -> Parser LocJs
forall a b. (a -> b) -> a -> b
$ Loc -> LocJs
LocJs (Loc -> LocJs) -> Loc -> LocJs
forall a b. (a -> b) -> a -> b
$ String -> String -> String -> CharPos -> CharPos -> Loc
Loc String
fn String
p String
m (Int
l, Int
c) (Int
l, Int
c)
instance FromJSON a => FromJSON (Item a) where
parseJSON :: Value -> Parser (Item a)
parseJSON = String -> (Object -> Parser (Item a)) -> Value -> Parser (Item a)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Item" Object -> Parser (Item a)
forall {a}. FromJSON a => Object -> Parser (Item a)
parseItem
where
parseItem :: Object -> Parser (Item a)
parseItem Object
o = Namespace
-> Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a
forall a.
Namespace
-> Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a
Item
(Namespace
-> Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> Parser Namespace
-> Parser
(Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Namespace
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"app"
Parser
(Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> Parser Environment
-> Parser
(Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Environment
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"env"
Parser
(Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> Parser Severity
-> Parser
(ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Severity
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"sev"
Parser
(ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> Parser ThreadIdText
-> Parser
(String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser ThreadIdText
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"thread"
Parser
(String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> Parser String
-> Parser
(ProcessID
-> a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"host"
Parser
(ProcessID
-> a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
-> Parser ProcessID
-> Parser
(a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ProcessIDJs -> ProcessID
getProcessIDJs (ProcessIDJs -> ProcessID)
-> Parser ProcessIDJs -> Parser ProcessID
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser ProcessIDJs
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"pid")
Parser (a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
-> Parser a
-> Parser (LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser a
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"data"
Parser (LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
-> Parser LogStr
-> Parser (UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser LogStr
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"msg"
Parser (UTCTime -> Namespace -> Maybe Loc -> Item a)
-> Parser UTCTime -> Parser (Namespace -> Maybe Loc -> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser UTCTime
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"at"
Parser (Namespace -> Maybe Loc -> Item a)
-> Parser Namespace -> Parser (Maybe Loc -> Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Namespace
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"ns"
Parser (Maybe Loc -> Item a)
-> Parser (Maybe Loc) -> Parser (Item a)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((LocJs -> Loc) -> Maybe LocJs -> Maybe Loc
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LocJs -> Loc
getLocJs (Maybe LocJs -> Maybe Loc)
-> Parser (Maybe LocJs) -> Parser (Maybe Loc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe LocJs)
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"loc")
processIDToText :: ProcessID -> Text
processIDToText :: ProcessID -> Text
processIDToText = ProcessID -> Text
forall a. Integral a => a -> Text
decimalToText
{-# INLINE processIDToText #-}
textToProcessID :: Text -> Maybe ProcessID
textToProcessID :: Text -> Maybe ProcessID
textToProcessID = String -> Maybe ProcessID
forall a. Read a => String -> Maybe a
readMay (String -> Maybe ProcessID)
-> (Text -> String) -> Text -> Maybe ProcessID
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
forall a b. StringConv a b => a -> b
toS
{-# INLINE textToProcessID #-}
newtype ProcessIDJs = ProcessIDJs {
ProcessIDJs -> ProcessID
getProcessIDJs :: ProcessID
}
instance ToJSON ProcessIDJs where
toJSON :: ProcessIDJs -> Value
toJSON (ProcessIDJs ProcessID
p) = Text -> Value
A.String (ProcessID -> Text
processIDToText ProcessID
p)
instance FromJSON ProcessIDJs where
parseJSON :: Value -> Parser ProcessIDJs
parseJSON = String
-> (Text -> Parser ProcessIDJs) -> Value -> Parser ProcessIDJs
forall a. String -> (Text -> Parser a) -> Value -> Parser a
A.withText String
"ProcessID" Text -> Parser ProcessIDJs
forall {m :: * -> *}. MonadFail m => Text -> m ProcessIDJs
parseProcessID
where
parseProcessID :: Text -> m ProcessIDJs
parseProcessID Text
t = case Text -> Maybe ProcessID
textToProcessID Text
t of
Just ProcessID
p -> ProcessIDJs -> m ProcessIDJs
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (ProcessIDJs -> m ProcessIDJs) -> ProcessIDJs -> m ProcessIDJs
forall a b. (a -> b) -> a -> b
$ ProcessID -> ProcessIDJs
ProcessIDJs ProcessID
p
Maybe ProcessID
Nothing -> String -> m ProcessIDJs
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m ProcessIDJs) -> String -> m ProcessIDJs
forall a b. (a -> b) -> a -> b
$ String
"Invalid ProcessIDJs " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a b. StringConv a b => a -> b
toS Text
t
data PayloadSelection
= AllKeys
| SomeKeys [Text]
deriving (Int -> PayloadSelection -> ShowS
[PayloadSelection] -> ShowS
PayloadSelection -> String
(Int -> PayloadSelection -> ShowS)
-> (PayloadSelection -> String)
-> ([PayloadSelection] -> ShowS)
-> Show PayloadSelection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PayloadSelection -> ShowS
showsPrec :: Int -> PayloadSelection -> ShowS
$cshow :: PayloadSelection -> String
show :: PayloadSelection -> String
$cshowList :: [PayloadSelection] -> ShowS
showList :: [PayloadSelection] -> ShowS
Show, PayloadSelection -> PayloadSelection -> Bool
(PayloadSelection -> PayloadSelection -> Bool)
-> (PayloadSelection -> PayloadSelection -> Bool)
-> Eq PayloadSelection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PayloadSelection -> PayloadSelection -> Bool
== :: PayloadSelection -> PayloadSelection -> Bool
$c/= :: PayloadSelection -> PayloadSelection -> Bool
/= :: PayloadSelection -> PayloadSelection -> Bool
Eq)
instance Semigroup PayloadSelection where
PayloadSelection
AllKeys <> :: PayloadSelection -> PayloadSelection -> PayloadSelection
<> PayloadSelection
_ = PayloadSelection
AllKeys
PayloadSelection
_ <> PayloadSelection
AllKeys = PayloadSelection
AllKeys
SomeKeys [Text]
as <> SomeKeys [Text]
bs = [Text] -> PayloadSelection
SomeKeys ([Text]
as [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text]
bs)
instance Monoid PayloadSelection where
mempty :: PayloadSelection
mempty = [Text] -> PayloadSelection
SomeKeys []
mappend :: PayloadSelection -> PayloadSelection -> PayloadSelection
mappend = PayloadSelection -> PayloadSelection -> PayloadSelection
forall a. Semigroup a => a -> a -> a
(<>)
equivalentPayloadSelection :: PayloadSelection -> PayloadSelection -> Bool
equivalentPayloadSelection :: PayloadSelection -> PayloadSelection -> Bool
equivalentPayloadSelection PayloadSelection
AllKeys PayloadSelection
AllKeys = Bool
True
equivalentPayloadSelection (SomeKeys [Text]
a) (SomeKeys [Text]
b) = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [Text]
a Set Text -> Set Text -> Bool
forall a. Eq a => a -> a -> Bool
== [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [Text]
b
equivalentPayloadSelection PayloadSelection
_ PayloadSelection
_ = Bool
False
{-# INLINE equivalentPayloadSelection #-}
class ToObject a where
toObject :: a -> A.Object
default toObject :: ToJSON a => a -> A.Object
toObject a
v = case a -> Value
forall a. ToJSON a => a -> Value
toJSON a
v of
A.Object Object
o -> Object
o
Value
_ -> Object
forall a. Monoid a => a
mempty
instance ToObject ()
instance ToObject A.Object
class ToObject a => LogItem a where
payloadKeys :: Verbosity -> a -> PayloadSelection
instance LogItem () where payloadKeys :: Verbosity -> () -> PayloadSelection
payloadKeys Verbosity
_ ()
_ = [Text] -> PayloadSelection
SomeKeys []
data AnyLogPayload = forall a. ToJSON a => AnyLogPayload a
newtype SimpleLogPayload = SimpleLogPayload {
SimpleLogPayload -> [(Text, AnyLogPayload)]
unSimpleLogPayload :: [(Text, AnyLogPayload)]
}
instance ToJSON SimpleLogPayload where
toJSON :: SimpleLogPayload -> Value
toJSON (SimpleLogPayload [(Text, AnyLogPayload)]
as) = [Pair] -> Value
object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$ ((Key, AnyLogPayload) -> Pair) -> [(Key, AnyLogPayload)] -> [Pair]
forall a b. (a -> b) -> [a] -> [b]
map (Key, AnyLogPayload) -> Pair
forall {e} {p}. KeyValue e p => (Key, AnyLogPayload) -> p
go [(Key, AnyLogPayload)]
as'
where go :: (Key, AnyLogPayload) -> p
go (Key
k, AnyLogPayload a
v) = Key
k Key -> a -> p
forall v. ToJSON v => Key -> v -> p
forall e kv v. (KeyValue e kv, ToJSON v) => Key -> v -> kv
A..= a
v
as' :: [(Key, AnyLogPayload)]
as' = (Text, AnyLogPayload) -> (Key, AnyLogPayload)
forall c. (Text, c) -> (Key, c)
toKey ((Text, AnyLogPayload) -> (Key, AnyLogPayload))
-> [(Text, AnyLogPayload)] -> [(Key, AnyLogPayload)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, AnyLogPayload)]
as
#if MIN_VERSION_aeson(2, 0, 0)
toKey :: (Text, c) -> (K.Key, c)
toKey :: forall c. (Text, c) -> (Key, c)
toKey = (Text -> Key) -> (Text, c) -> (Key, c)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Text -> Key
K.fromText
#else
toKey :: a -> a
toKey = id
#endif
{-# INLINE toKey #-}
instance ToObject SimpleLogPayload
instance LogItem SimpleLogPayload where
payloadKeys :: Verbosity -> SimpleLogPayload -> PayloadSelection
payloadKeys Verbosity
V0 SimpleLogPayload
_ = [Text] -> PayloadSelection
SomeKeys []
payloadKeys Verbosity
_ SimpleLogPayload
_ = PayloadSelection
AllKeys
instance Semigroup SimpleLogPayload where
SimpleLogPayload [(Text, AnyLogPayload)]
a <> :: SimpleLogPayload -> SimpleLogPayload -> SimpleLogPayload
<> SimpleLogPayload [(Text, AnyLogPayload)]
b = [(Text, AnyLogPayload)] -> SimpleLogPayload
SimpleLogPayload ([(Text, AnyLogPayload)]
a [(Text, AnyLogPayload)]
-> [(Text, AnyLogPayload)] -> [(Text, AnyLogPayload)]
forall a. Semigroup a => a -> a -> a
<> [(Text, AnyLogPayload)]
b)
instance Monoid SimpleLogPayload where
mempty :: SimpleLogPayload
mempty = [(Text, AnyLogPayload)] -> SimpleLogPayload
SimpleLogPayload []
mappend :: SimpleLogPayload -> SimpleLogPayload -> SimpleLogPayload
mappend = SimpleLogPayload -> SimpleLogPayload -> SimpleLogPayload
forall a. Semigroup a => a -> a -> a
(<>)
sl :: ToJSON a => Text -> a -> SimpleLogPayload
sl :: forall a. ToJSON a => Text -> a -> SimpleLogPayload
sl Text
a a
b = [(Text, AnyLogPayload)] -> SimpleLogPayload
SimpleLogPayload [(Text
a, a -> AnyLogPayload
forall a. ToJSON a => a -> AnyLogPayload
AnyLogPayload a
b)]
{-# INLINE sl #-}
payloadObject :: LogItem a => Verbosity -> a -> A.Object
payloadObject :: forall a. LogItem a => Verbosity -> a -> Object
payloadObject Verbosity
verb a
a = case (Verbosity -> PayloadSelection) -> [Verbosity] -> PayloadSelection
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
FT.foldMap ((Verbosity -> a -> PayloadSelection)
-> a -> Verbosity -> PayloadSelection
forall a b c. (a -> b -> c) -> b -> a -> c
flip Verbosity -> a -> PayloadSelection
forall a. LogItem a => Verbosity -> a -> PayloadSelection
payloadKeys a
a) [(Verbosity
V0)..Verbosity
verb] of
PayloadSelection
AllKeys -> a -> Object
forall a. ToObject a => a -> Object
toObject a
a
SomeKeys [Text]
ks -> [Text] -> Object -> Object
forall v. [Text] -> KeyMap v -> KeyMap v
filterElems [Text]
ks (Object -> Object) -> Object -> Object
forall a b. (a -> b) -> a -> b
$ a -> Object
forall a. ToObject a => a -> Object
toObject a
a
{-# INLINE payloadObject #-}
#if MIN_VERSION_aeson(2, 0, 0)
filterElems :: [Text] -> KM.KeyMap v -> KM.KeyMap v
filterElems :: forall v. [Text] -> KeyMap v -> KeyMap v
filterElems [Text]
ks = (Key -> v -> Bool) -> KeyMap v -> KeyMap v
forall v. (Key -> v -> Bool) -> KeyMap v -> KeyMap v
KM.filterWithKey (\ Key
k v
_ -> Key -> Text
K.toText Key
k Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`FT.elem` [Text]
ks)
#else
filterElems :: [Text] -> HM.HashMap Text v -> HM.HashMap Text v
filterElems ks = HM.filterWithKey (\ k _ -> k `FT.elem` ks)
#endif
{-# INLINE filterElems #-}
itemJson :: LogItem a => Verbosity -> Item a -> A.Value
itemJson :: forall a. LogItem a => Verbosity -> Item a -> Value
itemJson Verbosity
verb Item a
a = Item Object -> Value
forall a. ToJSON a => a -> Value
toJSON (Item Object -> Value) -> Item Object -> Value
forall a b. (a -> b) -> a -> b
$ Item a
a Item a -> (Item a -> Item Object) -> Item Object
forall a b. a -> (a -> b) -> b
& (a -> Identity Object) -> Item a -> Identity (Item Object)
forall a a (f :: * -> *).
Functor f =>
(a -> f a) -> Item a -> f (Item a)
itemPayload ((a -> Identity Object) -> Item a -> Identity (Item Object))
-> (a -> Object) -> Item a -> Item Object
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Verbosity -> a -> Object
forall a. LogItem a => Verbosity -> a -> Object
payloadObject Verbosity
verb
{-# INLINE itemJson #-}
type PermitFunc = forall a. Item a -> IO Bool
permitAND :: PermitFunc -> PermitFunc -> PermitFunc
permitAND :: PermitFunc -> PermitFunc -> PermitFunc
permitAND PermitFunc
f1 PermitFunc
f2 = \Item a
a -> (Bool -> Bool -> Bool) -> IO Bool -> IO Bool -> IO Bool
forall a b c. (a -> b -> c) -> IO a -> IO b -> IO c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Bool -> Bool -> Bool
(&&) (Item a -> IO Bool
PermitFunc
f1 Item a
a) (Item a -> IO Bool
PermitFunc
f2 Item a
a)
{-# INLINE permitAND #-}
permitOR :: PermitFunc -> PermitFunc -> PermitFunc
permitOR :: PermitFunc -> PermitFunc -> PermitFunc
permitOR PermitFunc
f1 PermitFunc
f2 = \Item a
a -> (Bool -> Bool -> Bool) -> IO Bool -> IO Bool -> IO Bool
forall a b c. (a -> b -> c) -> IO a -> IO b -> IO c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Bool -> Bool -> Bool
(||) (Item a -> IO Bool
PermitFunc
f1 Item a
a) (Item a -> IO Bool
PermitFunc
f2 Item a
a)
{-# INLINE permitOR #-}
data Scribe = Scribe {
Scribe -> forall a. LogItem a => Item a -> IO ()
liPush :: forall a. LogItem a => Item a -> IO ()
, Scribe -> IO ()
scribeFinalizer :: IO ()
, Scribe -> PermitFunc
scribePermitItem :: !PermitFunc
}
whenM :: Monad m => m Bool -> m () -> m ()
whenM :: forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM m Bool
mbool = m Bool -> (Bool -> m ()) -> m ()
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(>>=) m Bool
mbool ((Bool -> m ()) -> m ()) -> (m () -> Bool -> m ()) -> m () -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> m () -> m ()) -> m () -> Bool -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when
{-# INLINE whenM #-}
instance Semigroup Scribe where
(Scribe forall a. LogItem a => Item a -> IO ()
pushA IO ()
finA PermitFunc
permitA) <> :: Scribe -> Scribe -> Scribe
<> (Scribe forall a. LogItem a => Item a -> IO ()
pushB IO ()
finB PermitFunc
permitB) =
(forall a. LogItem a => Item a -> IO ())
-> IO () -> PermitFunc -> Scribe
Scribe (\Item a
item -> IO Bool -> IO () -> IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Item a -> IO Bool
PermitFunc
permitA Item a
item) (Item a -> IO ()
forall a. LogItem a => Item a -> IO ()
pushA Item a
item)
IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO Bool -> IO () -> IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Item a -> IO Bool
PermitFunc
permitB Item a
item) (Item a -> IO ()
forall a. LogItem a => Item a -> IO ()
pushB Item a
item)
)
(IO ()
finA IO () -> IO () -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadMask m) =>
m a -> m b -> m a
`finally` IO ()
finB)
(PermitFunc -> PermitFunc -> PermitFunc
permitOR Item a -> IO Bool
PermitFunc
permitA Item a -> IO Bool
PermitFunc
permitB)
{-# INLINE (<>) #-}
instance Monoid Scribe where
mempty :: Scribe
mempty = (forall a. LogItem a => Item a -> IO ())
-> IO () -> PermitFunc -> Scribe
Scribe (IO () -> Item a -> IO ()
forall a b. a -> b -> a
const (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ())) (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Severity -> Item a -> IO Bool
forall (m :: * -> *) a. Monad m => Severity -> Item a -> m Bool
permitItem Severity
DebugS)
{-# INLINE mempty #-}
mappend :: Scribe -> Scribe -> Scribe
mappend = Scribe -> Scribe -> Scribe
forall a. Semigroup a => a -> a -> a
(<>)
data ScribeHandle = ScribeHandle {
ScribeHandle -> Scribe
shScribe :: Scribe
, ScribeHandle -> TBQueue WorkerMessage
shChan :: BQ.TBQueue WorkerMessage
}
data WorkerMessage where
NewItem :: LogItem a => Item a -> WorkerMessage
PoisonPill :: WorkerMessage
permitItem :: Monad m => Severity -> Item a -> m Bool
permitItem :: forall (m :: * -> *) a. Monad m => Severity -> Item a -> m Bool
permitItem Severity
sev Item a
item = Bool -> m Bool
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Item a -> Severity
forall a. Item a -> Severity
_itemSeverity Item a
item Severity -> Severity -> Bool
forall a. Ord a => a -> a -> Bool
>= Severity
sev)
{-# INLINE permitItem #-}
data LogEnv = LogEnv {
LogEnv -> String
_logEnvHost :: HostName
, LogEnv -> ProcessID
_logEnvPid :: ProcessID
, LogEnv -> Namespace
_logEnvApp :: Namespace
, LogEnv -> Environment
_logEnvEnv :: Environment
, LogEnv -> IO UTCTime
_logEnvTimer :: IO UTCTime
, LogEnv -> Map Text ScribeHandle
_logEnvScribes :: M.Map Text ScribeHandle
}
makeLenses ''LogEnv
initLogEnv
:: Namespace
-> Environment
-> IO LogEnv
initLogEnv :: Namespace -> Environment -> IO LogEnv
initLogEnv Namespace
an Environment
env = String
-> ProcessID
-> Namespace
-> Environment
-> IO UTCTime
-> Map Text ScribeHandle
-> LogEnv
LogEnv
(String
-> ProcessID
-> Namespace
-> Environment
-> IO UTCTime
-> Map Text ScribeHandle
-> LogEnv)
-> IO String
-> IO
(ProcessID
-> Namespace
-> Environment
-> IO UTCTime
-> Map Text ScribeHandle
-> LogEnv)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO String
getHostName
IO
(ProcessID
-> Namespace
-> Environment
-> IO UTCTime
-> Map Text ScribeHandle
-> LogEnv)
-> IO ProcessID
-> IO
(Namespace
-> Environment -> IO UTCTime -> Map Text ScribeHandle -> LogEnv)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO ProcessID
getProcessID
IO
(Namespace
-> Environment -> IO UTCTime -> Map Text ScribeHandle -> LogEnv)
-> IO Namespace
-> IO
(Environment -> IO UTCTime -> Map Text ScribeHandle -> LogEnv)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Namespace -> IO Namespace
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
an
IO (Environment -> IO UTCTime -> Map Text ScribeHandle -> LogEnv)
-> IO Environment
-> IO (IO UTCTime -> Map Text ScribeHandle -> LogEnv)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Environment -> IO Environment
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Environment
env
IO (IO UTCTime -> Map Text ScribeHandle -> LogEnv)
-> IO (IO UTCTime) -> IO (Map Text ScribeHandle -> LogEnv)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> UpdateSettings UTCTime -> IO (IO UTCTime)
forall a. UpdateSettings a -> IO (IO a)
mkAutoUpdate UpdateSettings ()
defaultUpdateSettings { updateAction = getCurrentTime, updateFreq = 1000 }
IO (Map Text ScribeHandle -> LogEnv)
-> IO (Map Text ScribeHandle) -> IO LogEnv
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Map Text ScribeHandle -> IO (Map Text ScribeHandle)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map Text ScribeHandle
forall a. Monoid a => a
mempty
{-# INLINE initLogEnv#-}
registerScribe
:: Text
-> Scribe
-> ScribeSettings
-> LogEnv
-> IO LogEnv
registerScribe :: Text -> Scribe -> ScribeSettings -> LogEnv -> IO LogEnv
registerScribe Text
nm Scribe
scribe ScribeSettings {Int
_scribeBufferSize :: Int
_scribeBufferSize :: ScribeSettings -> Int
..} LogEnv
le = do
TBQueue WorkerMessage
queue <- STM (TBQueue WorkerMessage) -> IO (TBQueue WorkerMessage)
forall a. STM a -> IO a
atomically (Natural -> STM (TBQueue WorkerMessage)
forall a. Natural -> STM (TBQueue a)
BQ.newTBQueue (Int -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
_scribeBufferSize))
Async ()
worker <- Scribe -> TBQueue WorkerMessage -> IO (Async ())
spawnScribeWorker Scribe
scribe TBQueue WorkerMessage
queue
let fin :: IO ()
fin = do
STM () -> IO ()
forall a. STM a -> IO a
atomically (TBQueue WorkerMessage -> WorkerMessage -> STM ()
forall a. TBQueue a -> a -> STM ()
BQ.writeTBQueue TBQueue WorkerMessage
queue WorkerMessage
PoisonPill)
IO (Either SomeException ()) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Async () -> IO (Either SomeException ())
forall a. Async a -> IO (Either SomeException a)
Async.waitCatch Async ()
worker)
IO () -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Scribe -> IO ()
scribeFinalizer Scribe
scribe)
let sh :: ScribeHandle
sh = Scribe -> TBQueue WorkerMessage -> ScribeHandle
ScribeHandle (Scribe
scribe { scribeFinalizer = fin }) TBQueue WorkerMessage
queue
LogEnv -> IO LogEnv
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (LogEnv
le LogEnv -> (LogEnv -> LogEnv) -> LogEnv
forall a b. a -> (a -> b) -> b
& (Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv
Lens' LogEnv (Map Text ScribeHandle)
logEnvScribes ((Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv)
-> (Map Text ScribeHandle -> Map Text ScribeHandle)
-> LogEnv
-> LogEnv
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Text
-> ScribeHandle -> Map Text ScribeHandle -> Map Text ScribeHandle
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
nm ScribeHandle
sh)
{-# INLINE registerScribe#-}
spawnScribeWorker :: Scribe -> BQ.TBQueue WorkerMessage -> IO (Async.Async ())
spawnScribeWorker :: Scribe -> TBQueue WorkerMessage -> IO (Async ())
spawnScribeWorker (Scribe forall a. LogItem a => Item a -> IO ()
write IO ()
_ PermitFunc
_) TBQueue WorkerMessage
queue = IO () -> IO (Async ())
forall a. IO a -> IO (Async a)
Async.async IO ()
go
where
go :: IO ()
go = do
WorkerMessage
newCmd <- STM WorkerMessage -> IO WorkerMessage
forall a. STM a -> IO a
atomically (TBQueue WorkerMessage -> STM WorkerMessage
forall a. TBQueue a -> STM a
BQ.readTBQueue TBQueue WorkerMessage
queue)
case WorkerMessage
newCmd of
NewItem Item a
a -> do
IO (Either SomeException ()) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO () -> IO (Either SomeException ())
forall (m :: * -> *) a.
(HasCallStack, MonadCatch m) =>
m a -> m (Either SomeException a)
tryAny (Item a -> IO ()
forall a. LogItem a => Item a -> IO ()
write Item a
a))
IO ()
go
WorkerMessage
PoisonPill -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE spawnScribeWorker #-}
data ScribeSettings = ScribeSettings {
ScribeSettings -> Int
_scribeBufferSize :: Int
}
deriving (Int -> ScribeSettings -> ShowS
[ScribeSettings] -> ShowS
ScribeSettings -> String
(Int -> ScribeSettings -> ShowS)
-> (ScribeSettings -> String)
-> ([ScribeSettings] -> ShowS)
-> Show ScribeSettings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScribeSettings -> ShowS
showsPrec :: Int -> ScribeSettings -> ShowS
$cshow :: ScribeSettings -> String
show :: ScribeSettings -> String
$cshowList :: [ScribeSettings] -> ShowS
showList :: [ScribeSettings] -> ShowS
Show, ScribeSettings -> ScribeSettings -> Bool
(ScribeSettings -> ScribeSettings -> Bool)
-> (ScribeSettings -> ScribeSettings -> Bool) -> Eq ScribeSettings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScribeSettings -> ScribeSettings -> Bool
== :: ScribeSettings -> ScribeSettings -> Bool
$c/= :: ScribeSettings -> ScribeSettings -> Bool
/= :: ScribeSettings -> ScribeSettings -> Bool
Eq)
makeLenses ''ScribeSettings
defaultScribeSettings :: ScribeSettings
defaultScribeSettings :: ScribeSettings
defaultScribeSettings = Int -> ScribeSettings
ScribeSettings Int
4096
unregisterScribe
:: Text
-> LogEnv
-> LogEnv
unregisterScribe :: Text -> LogEnv -> LogEnv
unregisterScribe Text
nm = (Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv
Lens' LogEnv (Map Text ScribeHandle)
logEnvScribes ((Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv)
-> (Map Text ScribeHandle -> Map Text ScribeHandle)
-> LogEnv
-> LogEnv
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Text -> Map Text ScribeHandle -> Map Text ScribeHandle
forall k a. Ord k => k -> Map k a -> Map k a
M.delete Text
nm
clearScribes
:: LogEnv
-> LogEnv
clearScribes :: LogEnv -> LogEnv
clearScribes = (Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv
Lens' LogEnv (Map Text ScribeHandle)
logEnvScribes ((Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv)
-> Map Text ScribeHandle -> LogEnv -> LogEnv
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Map Text ScribeHandle
forall a. Monoid a => a
mempty
closeScribe
:: Text
-> LogEnv
-> IO LogEnv
closeScribe :: Text -> LogEnv -> IO LogEnv
closeScribe Text
nm LogEnv
le = do
IO () -> (ScribeHandle -> IO ()) -> Maybe ScribeHandle -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Scribe -> IO ()
scribeFinalizer (Scribe -> IO ())
-> (ScribeHandle -> Scribe) -> ScribeHandle -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScribeHandle -> Scribe
shScribe) (Text -> Map Text ScribeHandle -> Maybe ScribeHandle
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
nm (LogEnv -> Map Text ScribeHandle
_logEnvScribes LogEnv
le))
LogEnv -> IO LogEnv
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (LogEnv
le LogEnv -> (LogEnv -> LogEnv) -> LogEnv
forall a b. a -> (a -> b) -> b
& (Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv
Lens' LogEnv (Map Text ScribeHandle)
logEnvScribes ((Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv)
-> (Map Text ScribeHandle -> Map Text ScribeHandle)
-> LogEnv
-> LogEnv
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Text -> Map Text ScribeHandle -> Map Text ScribeHandle
forall k a. Ord k => k -> Map k a -> Map k a
M.delete Text
nm)
closeScribes
:: LogEnv
-> IO LogEnv
closeScribes :: LogEnv -> IO LogEnv
closeScribes LogEnv
le = do
let actions :: [IO ()]
actions = [IO LogEnv -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Text -> LogEnv -> IO LogEnv
closeScribe Text
k LogEnv
le) | Text
k <- Map Text ScribeHandle -> [Text]
forall k a. Map k a -> [k]
M.keys (LogEnv -> Map Text ScribeHandle
_logEnvScribes LogEnv
le)]
(IO () -> IO () -> IO ()) -> IO () -> [IO ()] -> IO ()
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
FT.foldr IO () -> IO () -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadMask m) =>
m a -> m b -> m a
finally (() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) [IO ()]
actions
LogEnv -> IO LogEnv
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (LogEnv
le LogEnv -> (LogEnv -> LogEnv) -> LogEnv
forall a b. a -> (a -> b) -> b
& (Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv
Lens' LogEnv (Map Text ScribeHandle)
logEnvScribes ((Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv)
-> Map Text ScribeHandle -> LogEnv -> LogEnv
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Map Text ScribeHandle
forall a. Monoid a => a
mempty)
class MonadIO m => Katip m where
getLogEnv :: m LogEnv
localLogEnv :: (LogEnv -> LogEnv) -> m a -> m a
instance Katip m => Katip (ReaderT s m) where
getLogEnv :: ReaderT s m LogEnv
getLogEnv = m LogEnv -> ReaderT s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> ReaderT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> ReaderT s m a -> ReaderT s m a
localLogEnv = (m a -> m a) -> ReaderT s m a -> ReaderT s m a
forall (m :: * -> *) a (n :: * -> *) b r.
(m a -> n b) -> ReaderT r m a -> ReaderT r n b
mapReaderT ((m a -> m a) -> ReaderT s m a -> ReaderT s m a)
-> ((LogEnv -> LogEnv) -> m a -> m a)
-> (LogEnv -> LogEnv)
-> ReaderT s m a
-> ReaderT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m a -> m a
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
#if !MIN_VERSION_either(4, 5, 0)
instance Katip m => Katip (EitherT s m) where
getLogEnv = lift getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv = mapEitherT . localLogEnv
{-# INLINE localLogEnv #-}
#endif
instance Katip m => Katip (ExceptT s m) where
getLogEnv :: ExceptT s m LogEnv
getLogEnv = m LogEnv -> ExceptT s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> ExceptT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> ExceptT s m a -> ExceptT s m a
localLogEnv = (m (Either s a) -> m (Either s a))
-> ExceptT s m a -> ExceptT s m a
forall (m :: * -> *) e a (n :: * -> *) e' b.
(m (Either e a) -> n (Either e' b))
-> ExceptT e m a -> ExceptT e' n b
mapExceptT ((m (Either s a) -> m (Either s a))
-> ExceptT s m a -> ExceptT s m a)
-> ((LogEnv -> LogEnv) -> m (Either s a) -> m (Either s a))
-> (LogEnv -> LogEnv)
-> ExceptT s m a
-> ExceptT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (Either s a) -> m (Either s a)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance Katip m => Katip (MaybeT m) where
getLogEnv :: MaybeT m LogEnv
getLogEnv = m LogEnv -> MaybeT m LogEnv
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> MaybeT m a -> MaybeT m a
localLogEnv = (m (Maybe a) -> m (Maybe a)) -> MaybeT m a -> MaybeT m a
forall (m :: * -> *) a (n :: * -> *) b.
(m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b
mapMaybeT ((m (Maybe a) -> m (Maybe a)) -> MaybeT m a -> MaybeT m a)
-> ((LogEnv -> LogEnv) -> m (Maybe a) -> m (Maybe a))
-> (LogEnv -> LogEnv)
-> MaybeT m a
-> MaybeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (Maybe a) -> m (Maybe a)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance Katip m => Katip (StateT s m) where
getLogEnv :: StateT s m LogEnv
getLogEnv = m LogEnv -> StateT s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> StateT s m a -> StateT s m a
localLogEnv = (m (a, s) -> m (a, s)) -> StateT s m a -> StateT s m a
forall (m :: * -> *) a s (n :: * -> *) b.
(m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
mapStateT ((m (a, s) -> m (a, s)) -> StateT s m a -> StateT s m a)
-> ((LogEnv -> LogEnv) -> m (a, s) -> m (a, s))
-> (LogEnv -> LogEnv)
-> StateT s m a
-> StateT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (a, s) -> m (a, s)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance (Katip m, Monoid w) => Katip (RWST r w s m) where
getLogEnv :: RWST r w s m LogEnv
getLogEnv = m LogEnv -> RWST r w s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> RWST r w s m a -> RWST r w s m a
localLogEnv = (m (a, s, w) -> m (a, s, w)) -> RWST r w s m a -> RWST r w s m a
forall (m :: * -> *) a s w (n :: * -> *) b w' r.
(m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
mapRWST ((m (a, s, w) -> m (a, s, w)) -> RWST r w s m a -> RWST r w s m a)
-> ((LogEnv -> LogEnv) -> m (a, s, w) -> m (a, s, w))
-> (LogEnv -> LogEnv)
-> RWST r w s m a
-> RWST r w s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (a, s, w) -> m (a, s, w)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance (Katip m, Monoid w) => Katip (Strict.RWST r w s m) where
getLogEnv :: RWST r w s m LogEnv
getLogEnv = m LogEnv -> RWST r w s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> RWST r w s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> RWST r w s m a -> RWST r w s m a
localLogEnv = (m (a, s, w) -> m (a, s, w)) -> RWST r w s m a -> RWST r w s m a
forall (m :: * -> *) a s w (n :: * -> *) b w' r.
(m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
Strict.mapRWST ((m (a, s, w) -> m (a, s, w)) -> RWST r w s m a -> RWST r w s m a)
-> ((LogEnv -> LogEnv) -> m (a, s, w) -> m (a, s, w))
-> (LogEnv -> LogEnv)
-> RWST r w s m a
-> RWST r w s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (a, s, w) -> m (a, s, w)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance Katip m => Katip (Strict.StateT s m) where
getLogEnv :: StateT s m LogEnv
getLogEnv = m LogEnv -> StateT s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> StateT s m a -> StateT s m a
localLogEnv = (m (a, s) -> m (a, s)) -> StateT s m a -> StateT s m a
forall (m :: * -> *) a s (n :: * -> *) b.
(m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
Strict.mapStateT ((m (a, s) -> m (a, s)) -> StateT s m a -> StateT s m a)
-> ((LogEnv -> LogEnv) -> m (a, s) -> m (a, s))
-> (LogEnv -> LogEnv)
-> StateT s m a
-> StateT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (a, s) -> m (a, s)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance (Katip m, Monoid s) => Katip (WriterT s m) where
getLogEnv :: WriterT s m LogEnv
getLogEnv = m LogEnv -> WriterT s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> WriterT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> WriterT s m a -> WriterT s m a
localLogEnv = (m (a, s) -> m (a, s)) -> WriterT s m a -> WriterT s m a
forall (m :: * -> *) a w (n :: * -> *) b w'.
(m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
mapWriterT ((m (a, s) -> m (a, s)) -> WriterT s m a -> WriterT s m a)
-> ((LogEnv -> LogEnv) -> m (a, s) -> m (a, s))
-> (LogEnv -> LogEnv)
-> WriterT s m a
-> WriterT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (a, s) -> m (a, s)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance (Katip m, Monoid s) => Katip (Strict.WriterT s m) where
getLogEnv :: WriterT s m LogEnv
getLogEnv = m LogEnv -> WriterT s m LogEnv
forall (m :: * -> *) a. Monad m => m a -> WriterT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> WriterT s m a -> WriterT s m a
localLogEnv = (m (a, s) -> m (a, s)) -> WriterT s m a -> WriterT s m a
forall (m :: * -> *) a w (n :: * -> *) b w'.
(m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
Strict.mapWriterT ((m (a, s) -> m (a, s)) -> WriterT s m a -> WriterT s m a)
-> ((LogEnv -> LogEnv) -> m (a, s) -> m (a, s))
-> (LogEnv -> LogEnv)
-> WriterT s m a
-> WriterT s m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m (a, s) -> m (a, s)
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
instance (Katip m) => Katip (ResourceT m) where
getLogEnv :: ResourceT m LogEnv
getLogEnv = m LogEnv -> ResourceT m LogEnv
forall (m :: * -> *) a. Monad m => m a -> ResourceT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
{-# INLINE getLogEnv #-}
localLogEnv :: forall a. (LogEnv -> LogEnv) -> ResourceT m a -> ResourceT m a
localLogEnv = (m a -> m a) -> ResourceT m a -> ResourceT m a
forall (m :: * -> *) a (n :: * -> *) b.
(m a -> n b) -> ResourceT m a -> ResourceT n b
transResourceT ((m a -> m a) -> ResourceT m a -> ResourceT m a)
-> ((LogEnv -> LogEnv) -> m a -> m a)
-> (LogEnv -> LogEnv)
-> ResourceT m a
-> ResourceT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> LogEnv) -> m a -> m a
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv
{-# INLINE localLogEnv #-}
newtype KatipT m a = KatipT { forall (m :: * -> *) a. KatipT m a -> ReaderT LogEnv m a
unKatipT :: ReaderT LogEnv m a }
deriving ( (forall a b. (a -> b) -> KatipT m a -> KatipT m b)
-> (forall a b. a -> KatipT m b -> KatipT m a)
-> Functor (KatipT m)
forall a b. a -> KatipT m b -> KatipT m a
forall a b. (a -> b) -> KatipT m a -> KatipT m b
forall (m :: * -> *) a b.
Functor m =>
a -> KatipT m b -> KatipT m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> KatipT m a -> KatipT m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> KatipT m a -> KatipT m b
fmap :: forall a b. (a -> b) -> KatipT m a -> KatipT m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> KatipT m b -> KatipT m a
<$ :: forall a b. a -> KatipT m b -> KatipT m a
Functor, Functor (KatipT m)
Functor (KatipT m) =>
(forall a. a -> KatipT m a)
-> (forall a b. KatipT m (a -> b) -> KatipT m a -> KatipT m b)
-> (forall a b c.
(a -> b -> c) -> KatipT m a -> KatipT m b -> KatipT m c)
-> (forall a b. KatipT m a -> KatipT m b -> KatipT m b)
-> (forall a b. KatipT m a -> KatipT m b -> KatipT m a)
-> Applicative (KatipT m)
forall a. a -> KatipT m a
forall a b. KatipT m a -> KatipT m b -> KatipT m a
forall a b. KatipT m a -> KatipT m b -> KatipT m b
forall a b. KatipT m (a -> b) -> KatipT m a -> KatipT m b
forall a b c.
(a -> b -> c) -> KatipT m a -> KatipT m b -> KatipT m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (KatipT m)
forall (m :: * -> *) a. Applicative m => a -> KatipT m a
forall (m :: * -> *) a b.
Applicative m =>
KatipT m a -> KatipT m b -> KatipT m a
forall (m :: * -> *) a b.
Applicative m =>
KatipT m a -> KatipT m b -> KatipT m b
forall (m :: * -> *) a b.
Applicative m =>
KatipT m (a -> b) -> KatipT m a -> KatipT m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> KatipT m a -> KatipT m b -> KatipT m c
$cpure :: forall (m :: * -> *) a. Applicative m => a -> KatipT m a
pure :: forall a. a -> KatipT m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
KatipT m (a -> b) -> KatipT m a -> KatipT m b
<*> :: forall a b. KatipT m (a -> b) -> KatipT m a -> KatipT m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> KatipT m a -> KatipT m b -> KatipT m c
liftA2 :: forall a b c.
(a -> b -> c) -> KatipT m a -> KatipT m b -> KatipT m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
KatipT m a -> KatipT m b -> KatipT m b
*> :: forall a b. KatipT m a -> KatipT m b -> KatipT m b
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
KatipT m a -> KatipT m b -> KatipT m a
<* :: forall a b. KatipT m a -> KatipT m b -> KatipT m a
Applicative, Applicative (KatipT m)
Applicative (KatipT m) =>
(forall a b. KatipT m a -> (a -> KatipT m b) -> KatipT m b)
-> (forall a b. KatipT m a -> KatipT m b -> KatipT m b)
-> (forall a. a -> KatipT m a)
-> Monad (KatipT m)
forall a. a -> KatipT m a
forall a b. KatipT m a -> KatipT m b -> KatipT m b
forall a b. KatipT m a -> (a -> KatipT m b) -> KatipT m b
forall (m :: * -> *). Monad m => Applicative (KatipT m)
forall (m :: * -> *) a. Monad m => a -> KatipT m a
forall (m :: * -> *) a b.
Monad m =>
KatipT m a -> KatipT m b -> KatipT m b
forall (m :: * -> *) a b.
Monad m =>
KatipT m a -> (a -> KatipT m b) -> KatipT m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
KatipT m a -> (a -> KatipT m b) -> KatipT m b
>>= :: forall a b. KatipT m a -> (a -> KatipT m b) -> KatipT m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
KatipT m a -> KatipT m b -> KatipT m b
>> :: forall a b. KatipT m a -> KatipT m b -> KatipT m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> KatipT m a
return :: forall a. a -> KatipT m a
Monad, Monad (KatipT m)
Monad (KatipT m) =>
(forall a. IO a -> KatipT m a) -> MonadIO (KatipT m)
forall a. IO a -> KatipT m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (KatipT m)
forall (m :: * -> *) a. MonadIO m => IO a -> KatipT m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> KatipT m a
liftIO :: forall a. IO a -> KatipT m a
MonadIO
, MonadCatch (KatipT m)
MonadCatch (KatipT m) =>
(forall b.
HasCallStack =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b)
-> (forall b.
HasCallStack =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b)
-> (forall a b c.
HasCallStack =>
KatipT m a
-> (a -> ExitCase b -> KatipT m c)
-> (a -> KatipT m b)
-> KatipT m (b, c))
-> MonadMask (KatipT m)
forall b.
HasCallStack =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b
forall a b c.
HasCallStack =>
KatipT m a
-> (a -> ExitCase b -> KatipT m c)
-> (a -> KatipT m b)
-> KatipT m (b, c)
forall (m :: * -> *). MonadMask m => MonadCatch (KatipT m)
forall (m :: * -> *) b.
(MonadMask m, HasCallStack) =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b
forall (m :: * -> *) a b c.
(MonadMask m, HasCallStack) =>
KatipT m a
-> (a -> ExitCase b -> KatipT m c)
-> (a -> KatipT m b)
-> KatipT m (b, c)
forall (m :: * -> *).
MonadCatch m =>
(forall b. HasCallStack => ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b.
HasCallStack =>
((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
HasCallStack =>
m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
$cmask :: forall (m :: * -> *) b.
(MonadMask m, HasCallStack) =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b
mask :: forall b.
HasCallStack =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b
$cuninterruptibleMask :: forall (m :: * -> *) b.
(MonadMask m, HasCallStack) =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b
uninterruptibleMask :: forall b.
HasCallStack =>
((forall a. KatipT m a -> KatipT m a) -> KatipT m b) -> KatipT m b
$cgeneralBracket :: forall (m :: * -> *) a b c.
(MonadMask m, HasCallStack) =>
KatipT m a
-> (a -> ExitCase b -> KatipT m c)
-> (a -> KatipT m b)
-> KatipT m (b, c)
generalBracket :: forall a b c.
HasCallStack =>
KatipT m a
-> (a -> ExitCase b -> KatipT m c)
-> (a -> KatipT m b)
-> KatipT m (b, c)
MonadMask, MonadThrow (KatipT m)
MonadThrow (KatipT m) =>
(forall e a.
(HasCallStack, Exception e) =>
KatipT m a -> (e -> KatipT m a) -> KatipT m a)
-> MonadCatch (KatipT m)
forall e a.
(HasCallStack, Exception e) =>
KatipT m a -> (e -> KatipT m a) -> KatipT m a
forall (m :: * -> *). MonadCatch m => MonadThrow (KatipT m)
forall (m :: * -> *) e a.
(MonadCatch m, HasCallStack, Exception e) =>
KatipT m a -> (e -> KatipT m a) -> KatipT m a
forall (m :: * -> *).
MonadThrow m =>
(forall e a.
(HasCallStack, Exception e) =>
m a -> (e -> m a) -> m a)
-> MonadCatch m
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, HasCallStack, Exception e) =>
KatipT m a -> (e -> KatipT m a) -> KatipT m a
catch :: forall e a.
(HasCallStack, Exception e) =>
KatipT m a -> (e -> KatipT m a) -> KatipT m a
MonadCatch, Monad (KatipT m)
Monad (KatipT m) =>
(forall e a. (HasCallStack, Exception e) => e -> KatipT m a)
-> MonadThrow (KatipT m)
forall e a. (HasCallStack, Exception e) => e -> KatipT m a
forall (m :: * -> *).
Monad m =>
(forall e a. (HasCallStack, Exception e) => e -> m a)
-> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (KatipT m)
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> KatipT m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> KatipT m a
throwM :: forall e a. (HasCallStack, Exception e) => e -> KatipT m a
MonadThrow, MonadIO (KatipT m)
MonadIO (KatipT m) =>
(forall a. ResourceT IO a -> KatipT m a)
-> MonadResource (KatipT m)
forall a. ResourceT IO a -> KatipT m a
forall (m :: * -> *).
MonadIO m =>
(forall a. ResourceT IO a -> m a) -> MonadResource m
forall (m :: * -> *). MonadResource m => MonadIO (KatipT m)
forall (m :: * -> *) a.
MonadResource m =>
ResourceT IO a -> KatipT m a
$cliftResourceT :: forall (m :: * -> *) a.
MonadResource m =>
ResourceT IO a -> KatipT m a
liftResourceT :: forall a. ResourceT IO a -> KatipT m a
MonadResource, (forall (m :: * -> *). Monad m => Monad (KatipT m)) =>
(forall (m :: * -> *) a. Monad m => m a -> KatipT m a)
-> MonadTrans KatipT
forall (m :: * -> *). Monad m => Monad (KatipT m)
forall (m :: * -> *) a. Monad m => m a -> KatipT m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *). Monad m => Monad (t m)) =>
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
$clift :: forall (m :: * -> *) a. Monad m => m a -> KatipT m a
lift :: forall (m :: * -> *) a. Monad m => m a -> KatipT m a
MonadTrans
, MonadBase b)
instance MonadIO m => Katip (KatipT m) where
getLogEnv :: KatipT m LogEnv
getLogEnv = ReaderT LogEnv m LogEnv -> KatipT m LogEnv
forall (m :: * -> *) a. ReaderT LogEnv m a -> KatipT m a
KatipT ReaderT LogEnv m LogEnv
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
localLogEnv :: forall a. (LogEnv -> LogEnv) -> KatipT m a -> KatipT m a
localLogEnv LogEnv -> LogEnv
f (KatipT ReaderT LogEnv m a
m) = ReaderT LogEnv m a -> KatipT m a
forall (m :: * -> *) a. ReaderT LogEnv m a -> KatipT m a
KatipT (ReaderT LogEnv m a -> KatipT m a)
-> ReaderT LogEnv m a -> KatipT m a
forall a b. (a -> b) -> a -> b
$ (LogEnv -> LogEnv) -> ReaderT LogEnv m a -> ReaderT LogEnv m a
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local LogEnv -> LogEnv
f ReaderT LogEnv m a
m
instance MonadTransControl KatipT where
type StT (KatipT) a = a
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run KatipT -> m a) -> KatipT m a
liftWith Run KatipT -> m a
f = ReaderT LogEnv m a -> KatipT m a
forall (m :: * -> *) a. ReaderT LogEnv m a -> KatipT m a
KatipT (ReaderT LogEnv m a -> KatipT m a)
-> ReaderT LogEnv m a -> KatipT m a
forall a b. (a -> b) -> a -> b
$ (LogEnv -> m a) -> ReaderT LogEnv m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((LogEnv -> m a) -> ReaderT LogEnv m a)
-> (LogEnv -> m a) -> ReaderT LogEnv m a
forall a b. (a -> b) -> a -> b
$ \LogEnv
le -> Run KatipT -> m a
f (Run KatipT -> m a) -> Run KatipT -> m a
forall a b. (a -> b) -> a -> b
$ \KatipT n b
t -> LogEnv -> KatipT n b -> n b
forall (m :: * -> *) a. LogEnv -> KatipT m a -> m a
runKatipT LogEnv
le KatipT n b
t
restoreT :: forall (m :: * -> *) a. Monad m => m (StT KatipT a) -> KatipT m a
restoreT = ReaderT LogEnv m a -> KatipT m a
forall (m :: * -> *) a. ReaderT LogEnv m a -> KatipT m a
KatipT (ReaderT LogEnv m a -> KatipT m a)
-> (m a -> ReaderT LogEnv m a) -> m a -> KatipT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LogEnv -> m a) -> ReaderT LogEnv m a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((LogEnv -> m a) -> ReaderT LogEnv m a)
-> (m a -> LogEnv -> m a) -> m a -> ReaderT LogEnv m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> LogEnv -> m a
forall a b. a -> b -> a
const
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance (MonadBaseControl b m) => MonadBaseControl b (KatipT m) where
type StM ((KatipT) m) a = ComposeSt (KatipT) m a
liftBaseWith :: forall a. (RunInBase (KatipT m) b -> b a) -> KatipT m a
liftBaseWith = (RunInBaseDefault KatipT m b -> b a) -> KatipT m a
(RunInBase (KatipT m) b -> b a) -> KatipT m a
forall (t :: (* -> *) -> * -> *) (b :: * -> *) (m :: * -> *) a.
(MonadTransControl t, MonadBaseControl b m) =>
(RunInBaseDefault t m b -> b a) -> t m a
defaultLiftBaseWith
restoreM :: forall a. StM (KatipT m) a -> KatipT m a
restoreM = ComposeSt KatipT m a -> KatipT m a
StM (KatipT m) a -> KatipT m a
forall (t :: (* -> *) -> * -> *) (b :: * -> *) (m :: * -> *) a.
(MonadTransControl t, MonadBaseControl b m) =>
ComposeSt t m a -> t m a
defaultRestoreM
instance MonadUnliftIO m => MonadUnliftIO (KatipT m) where
#if MIN_VERSION_unliftio_core(0, 2, 0)
withRunInIO :: forall b. ((forall a. KatipT m a -> IO a) -> IO b) -> KatipT m b
withRunInIO (forall a. KatipT m a -> IO a) -> IO b
inner = ReaderT LogEnv m b -> KatipT m b
forall (m :: * -> *) a. ReaderT LogEnv m a -> KatipT m a
KatipT (ReaderT LogEnv m b -> KatipT m b)
-> ReaderT LogEnv m b -> KatipT m b
forall a b. (a -> b) -> a -> b
$ (LogEnv -> m b) -> ReaderT LogEnv m b
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((LogEnv -> m b) -> ReaderT LogEnv m b)
-> (LogEnv -> m b) -> ReaderT LogEnv m b
forall a b. (a -> b) -> a -> b
$ \LogEnv
le -> ((forall a. m a -> IO a) -> IO b) -> m b
forall b. ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO b) -> m b)
-> ((forall a. m a -> IO a) -> IO b) -> m b
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
(forall a. KatipT m a -> IO a) -> IO b
inner (m a -> IO a
forall a. m a -> IO a
run (m a -> IO a) -> (KatipT m a -> m a) -> KatipT m a -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogEnv -> KatipT m a -> m a
forall (m :: * -> *) a. LogEnv -> KatipT m a -> m a
runKatipT LogEnv
le)
#else
askUnliftIO = KatipT $
withUnliftIO $ \u ->
pure (UnliftIO (unliftIO u . unKatipT))
#endif
#if MIN_VERSION_base(4, 9, 0)
instance MF.MonadFail m => MF.MonadFail (KatipT m) where
fail :: forall a. String -> KatipT m a
fail String
msg = m a -> KatipT m a
forall (m :: * -> *) a. Monad m => m a -> KatipT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (String -> m a
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
MF.fail String
msg)
{-# INLINE fail #-}
#endif
runKatipT :: LogEnv -> KatipT m a -> m a
runKatipT :: forall (m :: * -> *) a. LogEnv -> KatipT m a -> m a
runKatipT LogEnv
le (KatipT ReaderT LogEnv m a
f) = ReaderT LogEnv m a -> LogEnv -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT LogEnv m a
f LogEnv
le
{-# INLINE runKatipT #-}
katipNoLogging
:: ( Katip m
)
=> m a
-> m a
katipNoLogging :: forall (m :: * -> *) a. Katip m => m a -> m a
katipNoLogging = (LogEnv -> LogEnv) -> m a -> m a
forall a. (LogEnv -> LogEnv) -> m a -> m a
forall (m :: * -> *) a. Katip m => (LogEnv -> LogEnv) -> m a -> m a
localLogEnv (\LogEnv
le -> ((Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv)
-> Map Text ScribeHandle -> LogEnv -> LogEnv
forall s t a b. ASetter s t a b -> b -> s -> t
set (Map Text ScribeHandle -> Identity (Map Text ScribeHandle))
-> LogEnv -> Identity LogEnv
Lens' LogEnv (Map Text ScribeHandle)
logEnvScribes Map Text ScribeHandle
forall a. Monoid a => a
mempty LogEnv
le)
logItem
:: (A.Applicative m, LogItem a, Katip m)
=> a
-> Namespace
-> Maybe Loc
-> Severity
-> LogStr
-> m ()
logItem :: forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
a -> Namespace -> Maybe Loc -> Severity -> LogStr -> m ()
logItem a
a Namespace
ns Maybe Loc
loc Severity
sev LogStr
msg = do
LogEnv{String
IO UTCTime
Map Text ScribeHandle
ProcessID
Environment
Namespace
_logEnvHost :: LogEnv -> String
_logEnvPid :: LogEnv -> ProcessID
_logEnvApp :: LogEnv -> Namespace
_logEnvEnv :: LogEnv -> Environment
_logEnvTimer :: LogEnv -> IO UTCTime
_logEnvScribes :: LogEnv -> Map Text ScribeHandle
_logEnvHost :: String
_logEnvPid :: ProcessID
_logEnvApp :: Namespace
_logEnvEnv :: Environment
_logEnvTimer :: IO UTCTime
_logEnvScribes :: Map Text ScribeHandle
..} <- m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
Item a -> m ()
forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
Item a -> m ()
logKatipItem (Item a -> m ()) -> m (Item a) -> m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO (Item a) -> m (Item a)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
(Namespace
-> Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a
forall a.
Namespace
-> Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a
Item (Namespace
-> Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> IO Namespace
-> IO
(Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Namespace -> IO Namespace
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace
_logEnvApp
IO
(Environment
-> Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> IO Environment
-> IO
(Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Environment -> IO Environment
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Environment
_logEnvEnv
IO
(Severity
-> ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> IO Severity
-> IO
(ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Severity -> IO Severity
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Severity
sev
IO
(ThreadIdText
-> String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> IO ThreadIdText
-> IO
(String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ThreadId -> ThreadIdText
mkThreadIdText (ThreadId -> ThreadIdText) -> IO ThreadId -> IO ThreadIdText
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO ThreadId
myThreadId)
IO
(String
-> ProcessID
-> a
-> LogStr
-> UTCTime
-> Namespace
-> Maybe Loc
-> Item a)
-> IO String
-> IO
(ProcessID
-> a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> IO String
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
_logEnvHost
IO
(ProcessID
-> a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
-> IO ProcessID
-> IO (a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ProcessID -> IO ProcessID
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProcessID
_logEnvPid
IO (a -> LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
-> IO a
-> IO (LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> IO a
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a
IO (LogStr -> UTCTime -> Namespace -> Maybe Loc -> Item a)
-> IO LogStr -> IO (UTCTime -> Namespace -> Maybe Loc -> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LogStr -> IO LogStr
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LogStr
msg
IO (UTCTime -> Namespace -> Maybe Loc -> Item a)
-> IO UTCTime -> IO (Namespace -> Maybe Loc -> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> IO UTCTime
_logEnvTimer
IO (Namespace -> Maybe Loc -> Item a)
-> IO Namespace -> IO (Maybe Loc -> Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Namespace -> IO Namespace
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Namespace
_logEnvApp Namespace -> Namespace -> Namespace
forall a. Semigroup a => a -> a -> a
<> Namespace
ns)
IO (Maybe Loc -> Item a) -> IO (Maybe Loc) -> IO (Item a)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Loc -> IO (Maybe Loc)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Loc
loc)
{-# INLINE logItem#-}
logKatipItem
:: (A.Applicative m, LogItem a, Katip m)
=> Item a
-> m ()
logKatipItem :: forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
Item a -> m ()
logKatipItem Item a
item = do
LogEnv{String
IO UTCTime
Map Text ScribeHandle
ProcessID
Environment
Namespace
_logEnvHost :: LogEnv -> String
_logEnvPid :: LogEnv -> ProcessID
_logEnvApp :: LogEnv -> Namespace
_logEnvEnv :: LogEnv -> Environment
_logEnvTimer :: LogEnv -> IO UTCTime
_logEnvScribes :: LogEnv -> Map Text ScribeHandle
_logEnvHost :: String
_logEnvPid :: ProcessID
_logEnvApp :: Namespace
_logEnvEnv :: Environment
_logEnvTimer :: IO UTCTime
_logEnvScribes :: Map Text ScribeHandle
..} <- m LogEnv
forall (m :: * -> *). Katip m => m LogEnv
getLogEnv
IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$
[ScribeHandle] -> (ScribeHandle -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
FT.forM_ (Map Text ScribeHandle -> [ScribeHandle]
forall k a. Map k a -> [a]
M.elems Map Text ScribeHandle
_logEnvScribes) ((ScribeHandle -> IO ()) -> IO ())
-> (ScribeHandle -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ ScribeHandle {TBQueue WorkerMessage
Scribe
shScribe :: ScribeHandle -> Scribe
shChan :: ScribeHandle -> TBQueue WorkerMessage
shScribe :: Scribe
shChan :: TBQueue WorkerMessage
..} -> do
IO Bool -> IO () -> IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Scribe -> PermitFunc
scribePermitItem Scribe
shScribe Item a
item) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
IO Bool -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ STM Bool -> IO Bool
forall a. STM a -> IO a
atomically (TBQueue WorkerMessage -> WorkerMessage -> STM Bool
forall a. TBQueue a -> a -> STM Bool
tryWriteTBQueue TBQueue WorkerMessage
shChan (Item a -> WorkerMessage
forall a. LogItem a => Item a -> WorkerMessage
NewItem Item a
item))
{-# INLINE logKatipItem#-}
tryWriteTBQueue
:: TBQueue a
-> a
-> STM Bool
tryWriteTBQueue :: forall a. TBQueue a -> a -> STM Bool
tryWriteTBQueue TBQueue a
q a
a = do
Bool
full <- TBQueue a -> STM Bool
forall a. TBQueue a -> STM Bool
isFullTBQueue TBQueue a
q
Bool -> STM () -> STM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
full (TBQueue a -> a -> STM ()
forall a. TBQueue a -> a -> STM ()
writeTBQueue TBQueue a
q a
a)
Bool -> STM Bool
forall a. a -> STM a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> Bool
not Bool
full)
{-# INLINE tryWriteTBQueue#-}
logF
:: (Applicative m, LogItem a, Katip m)
=> a
-> Namespace
-> Severity
-> LogStr
-> m ()
logF :: forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
a -> Namespace -> Severity -> LogStr -> m ()
logF a
a Namespace
ns Severity
sev LogStr
msg = a -> Namespace -> Maybe Loc -> Severity -> LogStr -> m ()
forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
a -> Namespace -> Maybe Loc -> Severity -> LogStr -> m ()
logItem a
a Namespace
ns Maybe Loc
forall a. Maybe a
Nothing Severity
sev LogStr
msg
{-# INLINE logF#-}
logException
:: (Katip m, LogItem a, MonadCatch m, Applicative m)
=> a
-> Namespace
-> Severity
-> m b
-> m b
logException :: forall (m :: * -> *) a b.
(Katip m, LogItem a, MonadCatch m, Applicative m) =>
a -> Namespace -> Severity -> m b -> m b
logException a
a Namespace
ns Severity
sev m b
action = m b
action m b -> (SomeException -> m b) -> m b
forall (m :: * -> *) a.
(HasCallStack, MonadCatch m) =>
m a -> (SomeException -> m a) -> m a
`catchAny` \SomeException
e -> SomeException -> m ()
f SomeException
e m () -> m b -> m b
forall a b. m a -> m b -> m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SomeException -> m b
forall (m :: * -> *) e a.
(HasCallStack, MonadThrow m, Exception e) =>
e -> m a
throwM SomeException
e
where
f :: SomeException -> m ()
f SomeException
e = a -> Namespace -> Severity -> LogStr -> m ()
forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
a -> Namespace -> Severity -> LogStr -> m ()
logF a
a Namespace
ns Severity
sev (SomeException -> LogStr
forall a. Show a => a -> LogStr
msg SomeException
e)
msg :: a -> LogStr
msg a
e = Text -> LogStr
forall a. StringConv a Text => a -> LogStr
ls (String -> Text
T.pack String
"An exception has occurred: ") LogStr -> LogStr -> LogStr
forall a. Semigroup a => a -> a -> a
<> a -> LogStr
forall a. Show a => a -> LogStr
showLS a
e
logMsg
:: (Applicative m, Katip m)
=> Namespace
-> Severity
-> LogStr
-> m ()
logMsg :: forall (m :: * -> *).
(Applicative m, Katip m) =>
Namespace -> Severity -> LogStr -> m ()
logMsg Namespace
ns Severity
sev LogStr
msg = () -> Namespace -> Severity -> LogStr -> m ()
forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
a -> Namespace -> Severity -> LogStr -> m ()
logF () Namespace
ns Severity
sev LogStr
msg
liftLoc :: Loc -> Q Exp
liftLoc :: Loc -> Q Exp
liftLoc (Loc String
a String
b String
c (Int
d1, Int
d2) (Int
e1, Int
e2)) = [|Loc
$(String -> Q Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => String -> m Exp
TH.lift String
a)
$(String -> Q Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => String -> m Exp
TH.lift String
b)
$(String -> Q Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => String -> m Exp
TH.lift String
c)
($(Int -> Q Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int -> m Exp
TH.lift Int
d1), $(Int -> Q Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int -> m Exp
TH.lift Int
d2))
($(Int -> Q Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int -> m Exp
TH.lift Int
e1), $(Int -> Q Exp
forall t (m :: * -> *). (Lift t, Quote m) => t -> m Exp
forall (m :: * -> *). Quote m => Int -> m Exp
TH.lift Int
e2))
|]
#if MIN_VERSION_base(4, 8, 0)
getLoc :: HasCallStack => Maybe Loc
getLoc :: HasCallStack => Maybe Loc
getLoc = case CallStack -> [(String, SrcLoc)]
getCallStack CallStack
HasCallStack => CallStack
callStack of
[] -> Maybe Loc
forall a. Maybe a
Nothing
[(String, SrcLoc)]
xs -> Loc -> Maybe Loc
forall a. a -> Maybe a
Just (Loc -> Maybe Loc)
-> ([(String, SrcLoc)] -> Loc) -> [(String, SrcLoc)] -> Maybe Loc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String, SrcLoc) -> Loc
toLoc ((String, SrcLoc) -> Loc)
-> ([(String, SrcLoc)] -> (String, SrcLoc))
-> [(String, SrcLoc)]
-> Loc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(String, SrcLoc)] -> (String, SrcLoc)
forall a. HasCallStack => [a] -> a
head ([(String, SrcLoc)] -> Maybe Loc)
-> [(String, SrcLoc)] -> Maybe Loc
forall a b. (a -> b) -> a -> b
$ ((String, SrcLoc) -> Bool)
-> [(String, SrcLoc)] -> [(String, SrcLoc)]
forall a. (a -> Bool) -> [a] -> [a]
filter (String, SrcLoc) -> Bool
filterKatip [(String, SrcLoc)]
xs
where
filterKatip :: (String, SrcLoc) -> Bool
filterKatip :: (String, SrcLoc) -> Bool
filterKatip (String
_, SrcLoc
srcloc) = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$
String
"katip-" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` SrcLoc -> String
srcLocPackage SrcLoc
srcloc
toLoc :: (String, SrcLoc) -> Loc
toLoc :: (String, SrcLoc) -> Loc
toLoc (String
_, SrcLoc
l) = Loc {
loc_filename :: String
loc_filename = SrcLoc -> String
srcLocFile SrcLoc
l
, loc_package :: String
loc_package = SrcLoc -> String
srcLocPackage SrcLoc
l
, loc_module :: String
loc_module = SrcLoc -> String
srcLocModule SrcLoc
l
, loc_start :: CharPos
loc_start = (SrcLoc -> Int
srcLocStartLine SrcLoc
l, SrcLoc -> Int
srcLocStartCol SrcLoc
l)
, loc_end :: CharPos
loc_end = (SrcLoc -> Int
srcLocEndLine SrcLoc
l, SrcLoc -> Int
srcLocEndCol SrcLoc
l)
}
#else
getLoc :: Maybe Loc
getLoc = Nothing
#endif
getLocTH :: ExpQ
getLocTH :: Q Exp
getLocTH = [| $(Q Loc
location Q Loc -> (Loc -> Q Exp) -> Q Exp
forall a b. Q a -> (a -> Q b) -> Q b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Loc -> Q Exp
liftLoc) |]
logT :: ExpQ
logT :: Q Exp
logT = [| \ a ns sev msg -> logItem a ns (Just $(Q Exp
getLocTH)) sev msg |]
#if MIN_VERSION_base(4, 8, 0)
logLoc :: (Applicative m, LogItem a, Katip m, HasCallStack)
#else
logLoc :: (Applicative m, LogItem a, Katip m)
#endif
=> a
-> Namespace
-> Severity
-> LogStr
-> m ()
logLoc :: forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m, HasCallStack) =>
a -> Namespace -> Severity -> LogStr -> m ()
logLoc a
a Namespace
ns = a -> Namespace -> Maybe Loc -> Severity -> LogStr -> m ()
forall (m :: * -> *) a.
(Applicative m, LogItem a, Katip m) =>
a -> Namespace -> Maybe Loc -> Severity -> LogStr -> m ()
logItem a
a Namespace
ns Maybe Loc
HasCallStack => Maybe Loc
getLoc
locationToString :: Loc -> String
locationToString :: Loc -> String
locationToString Loc
loc = (Loc -> String
loc_package Loc
loc) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char
':' Char -> ShowS
forall a. a -> [a] -> [a]
: (Loc -> String
loc_module Loc
loc) String -> ShowS
forall a. [a] -> [a] -> [a]
++
Char
' ' Char -> ShowS
forall a. a -> [a] -> [a]
: (Loc -> String
loc_filename Loc
loc) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char
':' Char -> ShowS
forall a. a -> [a] -> [a]
: (Loc -> String
line Loc
loc) String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char
':' Char -> ShowS
forall a. a -> [a] -> [a]
: (Loc -> String
char Loc
loc)
where
line :: Loc -> String
line = Int -> String
forall a. Show a => a -> String
show (Int -> String) -> (Loc -> Int) -> Loc -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CharPos -> Int
forall a b. (a, b) -> a
fst (CharPos -> Int) -> (Loc -> CharPos) -> Loc -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Loc -> CharPos
loc_start
char :: Loc -> String
char = Int -> String
forall a. Show a => a -> String
show (Int -> String) -> (Loc -> Int) -> Loc -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CharPos -> Int
forall a b. (a, b) -> b
snd (CharPos -> Int) -> (Loc -> CharPos) -> Loc -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Loc -> CharPos
loc_start