Can anyone help me understand how to interpret the below function?
It appears to be an anonymous function, but has two sets of parenthesis.
function (j::JSON)(io, args)
(io, args)
are arguments to this function. But what does (j::JSON)
mean? How should I interpret this?
function (j::JSON)(io, args)
if j.recursive
logmsg = to_namedtuple(Any, args; nest_kwargs=j.nest_kwargs)
try
JSON3.write(io, logmsg)
catch e
if j.nest_kwargs
fallback_msg = to_namedtuple(String, args; nest_kwargs=true)
fallback_msg.kwargs["LoggingFormats.FormatError"] = sprint(showerror, e)
else
fallback_msg = (; to_namedtuple(String, args; nest_kwargs=false)..., Symbol("LoggingFormats.FormatError") => sprint(showerror, e))
end
JSON3.write(io, fallback_msg)
end
else
logmsg = to_namedtuple(String, args; nest_kwargs=j.nest_kwargs)
JSON3.write(io, logmsg)
end
println(io)
return nothing
end
This function comes from the LoggingFormats.jl
package.
It can be found here: