Skip to content

Commit

Permalink
Merge pull request #150 from sir4ur0n/support-payload-json-arrays
Browse files Browse the repository at this point in the history
feat: Support payload JSON arrays
  • Loading branch information
MichaelXavier committed Nov 30, 2023
2 parents 9a0eb8a + e47a203 commit f50cd5a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions katip/katip.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ library
, semigroups
, unliftio-core >= 0.1
, stm >= 2.4.4.1
, vector

hs-source-dirs: src
default-language: Haskell2010
Expand Down
4 changes: 3 additions & 1 deletion katip/src/Katip/Scribes/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import qualified Data.HashMap.Strict as HM
import Data.Monoid as M
import Data.Scientific as S
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Lazy (toStrict)
import Data.Text.Lazy.Builder
import Data.Text.Lazy.Encoding (decodeUtf8)
import Data.Text.Lazy.IO as T
import qualified Data.Vector as V
-------------------------------------------------------------------------------
import Katip.Core
import Katip.Format.Time (formatAsLogTime)
Expand Down Expand Up @@ -53,11 +55,11 @@ renderPair :: (Text, Value) -> [Builder]
renderPair (k, v) =
case v of
Object o -> concat [renderPair (k <> "." <> k', v') | (k', v') <- toTxtKeyList o]
Array a -> concat [renderPair (k <> "." <> T.pack (show k'), v') | (k', v') <- V.toList (V.indexed a)]
String t -> [fromText (k <> ":" <> t)]
Number n -> [fromText (k <> ":") <> fromString (formatNumber n)]
Bool b -> [fromText (k <> ":") <> fromString (show b)]
Null -> [fromText (k <> ":null")]
_ -> mempty -- Can't think of a sensible way to handle arrays
where
formatNumber :: Scientific -> String
formatNumber n =
Expand Down
2 changes: 1 addition & 1 deletion katip/test/Katip/Tests/Scribes/Handle-text-aeson2.golden
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ newline][Info][example][PID 7331][ThreadId 1337][note.deep:some note] message
[2016-06-12 12:34:56][foo][Info][example][PID 7331][ThreadId 1337][note.deep:some note][main:Some.Module path/Some/Module.hs:30:1] message
[2016-06-12 12:34:56][foo][Info][example][PID 7331][ThreadId 1337][note.deep:some note][main:Some.Module путь/Some/Module.hs:3000:9000] message
[2016-06-12 12:34:56][foo][Info][example][PID 7331][ThreadId 1337][float:0][num:0][sub:null][text:] message
[2016-06-12 12:34:56][foo][Info][example][PID 7331][ThreadId 1337][float:5.5][num:10][sub.note.deep:some note][text:note] message
[2016-06-12 12:34:56][foo][Info][example][PID 7331][ThreadId 1337][float:5.5][list.0:one][list.1:two][list.2:three][num:10][sub.note.deep:some note][text:note] message
4 changes: 1 addition & 3 deletions katip/test/Katip/Tests/Scribes/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ setupFile = do

-- Following code tests Handle scribe output against a golden file.
-- This test will fail on non utf8 locales because golden file is in utf-8.
-- It generates all meaningfull variations of Item, and also tests
-- It generates all meaningful variations of Item, and also tests
-- writing of payload of different Aeson constructors
--
-- Note: currently Handle scribe does not write Array items at all
-------------------------------------------------------------------------------
data AllTypesLogItem = AllTypesLogItem
{ atlText :: Text,
Expand Down

0 comments on commit f50cd5a

Please sign in to comment.