Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support payload JSON arrays #150

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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