Skip to content

Commit

Permalink
fix: Fixes for 1.6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
curtd committed May 28, 2023
1 parent 40b6928 commit cdee20d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
Dictionaries = "0.3"
PrecompileTools = "1"
julia = "1.6"
PrecompileTools = "1"
6 changes: 6 additions & 0 deletions src/levels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const LogLevelIntType = fieldtype(LogLevel, :level)
const NotSet = LogLevel(typemin(LogLevelIntType))

const All = NotSet + 1
if VERSION < v"1.8"
const Debug = Logging.Debug
const Info = Logging.Info
const Error = Logging.Error
const Warn = Logging.Warn
end
const Trace = Debug - 1
const Notice = Info + 1
const Critical = Error + 1
Expand Down
21 changes: 11 additions & 10 deletions src/records.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,29 @@ function RuntimeLogRecordMetadata(; datetime::DateTime=Dates.now(), thread_id::I
end

"""
LogRecordData
LogRecordData(data)
LogRecordData(args::Pair{Symbol, <:Any}...)
A type representing an optional collection of `key => value` pairs attached to a log record.
"""
struct LogRecordData
data::Union{Nothing,Vector{Pair{Symbol, Any}}}
function LogRecordData(d; exclude::Union{Symbol,Vector{Symbol}}=Symbol[])
if !isnothing(d) && !isempty(d)
_exclude = exclude isa Symbol ? [exclude] : exclude
return new([convert(Pair{Symbol,Any}, di) for di in d if first(di) _exclude])
else
return new(nothing)
end
end
end
Base.isempty(l::LogRecordData) = isnothing(l.data) || isempty(l.data)
Base.length(l::LogRecordData) = isnothing(l.data) ? 0 : length(l.data)
Base.pairs(l::LogRecordData) = isnothing(l.data) ? pairs((;)) : l.data
Base.iterate(l::LogRecordData) = isnothing(l.data) ? nothing : iterate(l.data)
Base.iterate(l::LogRecordData, st) = isnothing(st) ? nothing : iterate(l.data, st)

function LogRecordData(d::Union{Base.Pairs, Vector{Pair{Symbol, <:Any}}}; exclude::Union{Symbol,Vector{Symbol}}=Symbol[])
if !isempty(d)
_exclude = exclude isa Symbol ? [exclude] : exclude
return LogRecordData([convert(Pair{Symbol,Any}, di) for di in d if first(di) _exclude])
else
return LogRecordData(nothing)
end
end

function LogRecordData(args::Pair{Symbol, <:Any}...)
if !isempty(args)
return LogRecordData(collect(args))
Expand Down

0 comments on commit cdee20d

Please sign in to comment.