pretty json object logs
This commit is contained in:
parent
3eee205eaf
commit
250f3bd2a0
4 changed files with 15 additions and 2 deletions
|
@ -130,7 +130,7 @@ noteToCreate note = Fedi.makeCreateNote note
|
||||||
handleInbox :: DB -> FilePath -> Fedi.AnyActivity -> Twain.ResponderM Twain.Response
|
handleInbox :: DB -> FilePath -> Fedi.AnyActivity -> Twain.ResponderM Twain.Response
|
||||||
handleInbox db detailsFile activity = do
|
handleInbox db detailsFile activity = do
|
||||||
details <- liftIO $ fetchUserDetails detailsFile
|
details <- liftIO $ fetchUserDetails detailsFile
|
||||||
Log.logDebug (Fedi.pShow activity)
|
Log.logDebug (Fedi.pJson activity)
|
||||||
case activity of
|
case activity of
|
||||||
Fedi.ActivityFollow follow -> do
|
Fedi.ActivityFollow follow -> do
|
||||||
let
|
let
|
||||||
|
@ -197,7 +197,7 @@ handleInbox db detailsFile activity = do
|
||||||
|
|
||||||
sendFollowers :: Fedi.UserDetails -> DB -> Fedi.AnyActivity -> IO ()
|
sendFollowers :: Fedi.UserDetails -> DB -> Fedi.AnyActivity -> IO ()
|
||||||
sendFollowers details db message = do
|
sendFollowers details db message = do
|
||||||
Log.logDebug $ "Sending to followers: " <> Fedi.pShow message
|
Log.logDebug $ "Sending to followers: " <> Fedi.pJson message
|
||||||
followers <- db.getFollowers
|
followers <- db.getFollowers
|
||||||
Fedi.for_ followers \follower -> do
|
Fedi.for_ followers \follower -> do
|
||||||
Async.async $ do
|
Async.async $ do
|
||||||
|
|
|
@ -66,6 +66,7 @@ library
|
||||||
, http-types
|
, http-types
|
||||||
, simple-logger
|
, simple-logger
|
||||||
, pretty-simple
|
, pretty-simple
|
||||||
|
, aeson-pretty
|
||||||
|
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: GHC2021
|
default-language: GHC2021
|
||||||
|
|
|
@ -19,6 +19,9 @@ import Data.Function as Export
|
||||||
import Control.Monad.Catch as Export (throwM, Exception, MonadThrow)
|
import Control.Monad.Catch as Export (throwM, Exception, MonadThrow)
|
||||||
import Text.Pretty.Simple qualified as PS
|
import Text.Pretty.Simple qualified as PS
|
||||||
import Data.Text.Lazy qualified as TL
|
import Data.Text.Lazy qualified as TL
|
||||||
|
import Data.Text.Lazy.Encoding qualified as TL
|
||||||
|
import Data.Aeson qualified as A
|
||||||
|
import Data.Aeson.Encode.Pretty qualified as AP
|
||||||
|
|
||||||
data Error
|
data Error
|
||||||
= Error String
|
= Error String
|
||||||
|
@ -29,3 +32,9 @@ throw = throwM . Error
|
||||||
|
|
||||||
pShow :: Show a => a -> Text
|
pShow :: Show a => a -> Text
|
||||||
pShow = TL.toStrict . PS.pShow
|
pShow = TL.toStrict . PS.pShow
|
||||||
|
|
||||||
|
pJson :: A.ToJSON a => a -> Text
|
||||||
|
pJson =
|
||||||
|
TL.toStrict
|
||||||
|
. TL.decodeUtf8
|
||||||
|
. AP.encodePretty' AP.defConfig { AP.confIndent = AP.Spaces 2 }
|
||||||
|
|
|
@ -21,6 +21,9 @@ sendPost
|
||||||
-> IO ByteString
|
-> IO ByteString
|
||||||
sendPost details url payload = do
|
sendPost details url payload = do
|
||||||
uri <- URI.mkURI $ fromString url
|
uri <- URI.mkURI $ fromString url
|
||||||
|
Log.logDebug "To: " <> fromString url
|
||||||
|
Log.logDebug "Sending: " <> pJson payload
|
||||||
|
|
||||||
let encoded = BSL.toStrict $ A.encode payload
|
let encoded = BSL.toStrict $ A.encode payload
|
||||||
httpSignature <- makeHttpSignature details uri encoded
|
httpSignature <- makeHttpSignature details uri encoded
|
||||||
Log.logDebug $ "http signature: " <> pShow httpSignature
|
Log.logDebug $ "http signature: " <> pShow httpSignature
|
||||||
|
|
Loading…
Add table
Reference in a new issue