@@ -2,7 +2,7 @@ using Test: @test, @testset, @test_throws
22using Logging: Logging, with_logger
33using LoggingExtras: FormatLogger
44using LoggingFormats: LoggingFormats, Truncated, JSON, LogFmt
5- import JSON3
5+ import JSON as JSONLib
66
77function my_throwing_function ()
88 throw (ArgumentError (" no" ))
7070 @warn " warn msg"
7171 @error " error msg"
7272 end
73- json = [JSON3 . read (x) for x in eachline (seekstart (io))]
73+ json = [JSONLib . parse (x) for x in eachline (seekstart (io))]
7474 @test json[1 ]. level == " debug"
7575 @test json[1 ]. msg == " debug msg"
7676 @test json[2 ]. level == " info"
9090 y = (1 , 2 )
9191 @info " info msg" x = [1 , 2 , 3 ] y
9292 end
93- json = JSON3 . read (seekstart (io))
93+ json = JSONLib . parse (seekstart (io))
9494 @test json. level == " info"
9595 @test json. msg == " info msg"
9696 @test json. module == " Main"
105105 y = (1 , 2 )
106106 @info " info msg" x = [1 , 2 , 3 ] y
107107 end
108- json = JSON3 . read (seekstart (io))
108+ json = JSONLib . parse (seekstart (io))
109109 @test json. level == " info"
110110 @test json. msg == " info msg"
111111 @test json. module == " Main"
120120 with_logger (FormatLogger (JSON (; nest_kwargs= false ), io)) do
121121 @info " info msg" line = [1 , 2 , 3 ]
122122 end
123- json = JSON3 . read (seekstart (io))
123+ json = JSONLib . parse (seekstart (io))
124124 @test json. level == " info"
125125 @test json. msg == " info msg"
126126 @test json. module == " Main"
@@ -133,32 +133,32 @@ end
133133 with_logger (FormatLogger (JSON (; recursive= true ), io)) do
134134 @info " info msg" x = [1 , 2 , 3 ] y = Dict (" hi" => Dict (" hi2" => [1 ,2 ]))
135135 end
136- json = JSON3 . read (seekstart (io))
136+ json = JSONLib . parse (seekstart (io))
137137 @test json. level == " info"
138138 @test json. msg == " info msg"
139139 @test json. module == " Main"
140140 @test json. line isa Int
141141 @test json. kwargs. x == [1 , 2 , 3 ]
142- @test json. kwargs. y == Dict (:hi => Dict (: hi2 => [1 ,2 ]))
142+ @test json. kwargs. y == Dict (" hi " => Dict (" hi2" => [1 ,2 ]))
143143
144144 # Fallback to strings
145145 for nest_kwargs in (true , false )
146146 io = IOBuffer ()
147147 with_logger (FormatLogger (JSON (; recursive= true , nest_kwargs= nest_kwargs), io)) do
148148 @info " info msg" x = [1 , 2 , 3 ] y = Dict (" hi" => NaN )
149149 end
150- json = JSON3 . read (seekstart (io))
150+ json = JSONLib . parse (seekstart (io))
151151 @test json. level == " info"
152152 @test json. msg == " info msg"
153153 @test json. module == " Main"
154154 @test json. line isa Int
155155 if nest_kwargs
156156 @test json. kwargs. x == " [1, 2, 3]"
157- @test json . kwargs[ Symbol ( " LoggingFormats.FormatError " )] == " NaN not allowed to be written in JSON spec"
157+ @test occursin ( " NaN not allowed to be written in JSON spec" , json . kwargs[ Symbol ( " LoggingFormats.FormatError " )])
158158 y = json. kwargs. y
159159 else
160160 @test json. x == " [1, 2, 3]"
161- @test json[ Symbol ( " LoggingFormats.FormatError " )] == " NaN not allowed to be written in JSON spec"
161+ @test occursin ( " NaN not allowed to be written in JSON spec" , json[ Symbol ( " LoggingFormats.FormatError " )])
162162 y = json. y
163163 end
164164 must_have = (" Dict" , " \" hi\" " , " =>" , " NaN" )
172172 with_logger (FormatLogger (JSON (; recursive= recursive, nest_kwargs= nest_kwargs), io)) do
173173 @error " Oh no" exception = ArgumentError (" no" )
174174 end
175- logs = JSON3 . read (seekstart (io))
175+ logs = JSONLib . parse (seekstart (io))
176176 @test logs[" msg" ] == " Oh no"
177177 ex = nest_kwargs ? logs[" kwargs" ][" exception" ] : logs[" exception" ]
178178 @test ex == " ArgumentError: no"
182182 with_logger (FormatLogger (JSON (; recursive= recursive, nest_kwargs= nest_kwargs), io)) do
183183 @error " Oh no" ex = ArgumentError (" no" )
184184 end
185- logs = JSON3 . read (seekstart (io))
185+ logs = JSONLib . parse (seekstart (io))
186186 @test logs[" msg" ] == " Oh no"
187187 ex = nest_kwargs ? logs[" kwargs" ][" ex" ] : logs[" ex" ]
188188 @test ex == " ArgumentError: no"
196196 @error " Oh no" exception = (e, catch_backtrace ())
197197 end
198198 end
199- logs = JSON3 . read (seekstart (io))
199+ logs = JSONLib . parse (seekstart (io))
200200 @test logs[" msg" ] == " Oh no"
201201
202202 ex = nest_kwargs ? logs[" kwargs" ][" exception" ] : logs[" exception" ]
279279 # write(in, str)
280280 # close(in)
281281 # wait(p)
282- # output = JSON3.read (read(out))
282+ # output = JSONLib.parse (read(out))
283283end
0 commit comments