Skip to content

No Base.isless method for Int32 and LogLevel #10

@MarkNahabedian

Description

@MarkNahabedian

I expect somewhere the code is being inconsistent about integers versus LogLevels. I'm not going to guess how to resolve it.

using Logging
using Logging2

let
    io = Logging2.LineBufferedIO(Logging2.LoggingStream(current_logger();
                                                        id="bug",
                                                        level=Logging.Info))
    
    println(io, "Log message")
end

ERROR: MethodError: no method matching isless(::Int32, ::LogLevel)
The function `isless` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  isless(!Matched::LogLevel, ::LogLevel)
   @ Base logging/logging.jl:131
  isless(!Matched::Missing, ::Any)
   @ Base missing.jl:87
  isless(::Real, !Matched::AbstractFloat)
   @ Base operators.jl:223
  ...

Stacktrace:
  [1] <(x::Int32, y::LogLevel)
    @ Base ./operators.jl:399
  [2] <=(x::Int32, y::LogLevel)
    @ Base ./operators.jl:448
  [3] >=(x::LogLevel, y::Int32)
    @ Base ./operators.jl:472
  [4] unsafe_write(s::Logging2.LoggingStream{ConsoleLogger, LogLevel}, p::Ptr{UInt8}, n::UInt64)
    @ Logging2 ~/.julia/packages/Logging2/MNTyk/src/LoggingStream.jl:34
  [5] unsafe_write(s::Logging2.LoggingStream{ConsoleLogger, LogLevel}, p::Ptr{UInt8}, n::Int64)
    @ Base ./io.jl:803
  [6] write(s::Logging2.LoggingStream{ConsoleLogger, LogLevel}, A::Vector{UInt8})
    @ Base ./io.jl:837
  [7] unsafe_write(io::Logging2.LineBufferedIO{Logging2.LoggingStream{ConsoleLogger, LogLevel}}, p::Ptr{UInt8}, n::UInt64)
    @ Logging2 ~/.julia/packages/Logging2/MNTyk/src/LineBufferedIO.jl:66
  [8] write
    @ ./strings/io.jl:246 [inlined]
  [9] print
    @ ./strings/io.jl:248 [inlined]
 [10] print(::Logging2.LineBufferedIO{Logging2.LoggingStream{ConsoleLogger, LogLevel}}, ::String, ::String)
    @ Base ./strings/io.jl:46
 [11] println(io::Logging2.LineBufferedIO{Logging2.LoggingStream{ConsoleLogger, LogLevel}}, xs::String)
    @ Base ./strings/io.jl:77
 [12] top-level scope
    @ none:6

My yworkaround for now is

Base.isless(a::Int32, b::Logging.LogLevel) = isless(a, convert(Int32, b))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions