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

fix: Fix missing key-type specifying LogRecord constructor #7

Merged
merged 1 commit into from
Apr 23, 2024
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
9 changes: 6 additions & 3 deletions src/records.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ struct LogRecordData{K}
LogRecordData{K}() where {K} = new(Dictionary{K, Any}())
end
@define_interface LogRecordData interface=equality
@forward_methods LogRecordData field=data Base.isempty(_) Base.length(_) Base.pairs(_)
@forward_methods LogRecordData field=data Base.isempty(_) Base.length(_) Base.pairs(_) Base.get(_, key, default) Base.haskey(_, key)
Base.eltype(::Type{LogRecordData{K}}) where {K} = Pair{K, Any}
Base.iterate(d::LogRecordData) = iterate(pairs(d.data))
Base.iterate(d::LogRecordData, st) = iterate(pairs(d.data), st)
Base.collect(d::LogRecordData) = collect(pairs(d.data))
Base.@propagate_inbounds Base.getindex(d::LogRecordData, key) = getindex(d.data, key)

"""
add_record_data!(r, data::Pair)
Expand Down Expand Up @@ -124,7 +125,7 @@ log_record_data() = _log_record_data(Symbol, ())

LogRecordData(::Nothing; kwargs...) = _log_record_data(Symbol, (); kwargs...)
LogRecordData(data; kwargs...) = log_record_data(data; kwargs...)
LogRecordData(args::Pair{Symbol, <:Any}...; kwargs...) = _log_record_data(Symbol, args; kwargs...)
LogRecordData(args::Pair...; kwargs...) = log_record_data(args; kwargs...)



Expand Down Expand Up @@ -210,7 +211,9 @@ end

LogRecord(static_meta::StaticLogRecordMetadata, runtime_meta::RuntimeLogRecordMetadata, record::AbstractLogRecord, data::LogRecordData) = LogRecord{typeof(record)}(static_meta, runtime_meta, data, record)

LogRecord(static_meta::StaticLogRecordMetadata, runtime_meta::RuntimeLogRecordMetadata, record::AbstractLogRecord, args::Pair{<:Any, <:Any}...) = LogRecord(static_meta, runtime_meta, record, LogRecordData(args...))
LogRecord(static_meta::StaticLogRecordMetadata, runtime_meta::RuntimeLogRecordMetadata, record::AbstractLogRecord, arg1::Pair{<:Any,<:Any}, args::Pair{<:Any, <:Any}...) = LogRecord(static_meta, runtime_meta, record, log_record_data((arg1, args...)))

LogRecord(static_meta::StaticLogRecordMetadata, runtime_meta::RuntimeLogRecordMetadata, record::AbstractLogRecord, DataKeyType::Type=Symbol) = LogRecord(static_meta, runtime_meta, record, log_record_data(DataKeyType, ()))

LogRecord(static_meta::StaticLogRecordMetadata, record::AbstractLogRecord, args...; runtime_meta::RuntimeLogRecordMetadata=RuntimeLogRecordMetadata()) = LogRecord(static_meta, runtime_meta, record, args...)

Expand Down
5 changes: 5 additions & 0 deletions test/TestLoggingCommon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ module TestLoggingCommon
@Test v == String
end
end
d[:a] == 1
d[:b] == String
@Test haskey(d, :a)
@Test haskey(d, :c) == false
@Test get(d, :c, nothing) |> isnothing
d = log_record_data(("a" => 1, "b" => 2); exclude="a")
@Test collect(d) == ["b" => 2]
@Test d == log_record_data(String, ("a" => 1, "b" => 2); exclude="a")
Expand Down
Loading