Skip to content

Commit

Permalink
fix: Fix module_str_trim_main method (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
curtd authored Apr 24, 2024
1 parent 333b5fb commit 417f002
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/records.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function module_str_trim_main(_module::Module)
name = fullname(_module)
if first(name) == :Main && length(name) > 1
return join(view(name, 2:length(name)), '.')
return join(name[2:length(name)], '.')
else
return join(name, '.')
end
Expand Down Expand Up @@ -31,13 +31,13 @@ log_level_name(meta::StaticLogRecordMetadata) = meta.level_name

_filename(line::LineNumberNode) = !isnothing(line.file) ? string(line.file) : nothing

function StaticLogRecordMetadata(source::AbstractString, level::LogLevel, level_name::String, filename::Union{String, Nothing}, line_num::Int, group=nothing, id=nothing)
return StaticLogRecordMetadata(string(source), level, level_name, something(filename, "?"), line_num, group, id)
function StaticLogRecordMetadata(source::AbstractString, level::LogLevel, level_name::String, filename::Union{String, Nothing}, line_num::Union{Int, Nothing}, group=nothing, id=nothing)
return StaticLogRecordMetadata(string(source), level, level_name, something(filename, i""), something(line_num, 0), group, id)
end

StaticLogRecordMetadata(source::AbstractString, level::LogLevel, lnn::LineNumberNode, args...) = StaticLogRecordMetadata(source, level, "", _filename(lnn), lnn.line, args...)
StaticLogRecordMetadata(source::AbstractString, level::LogLevel, lnn::LineNumberNode, args...) = StaticLogRecordMetadata(source, level, i"", _filename(lnn), lnn.line, args...)

StaticLogRecordMetadata(source::AbstractString, level::LogLevel, filename::Union{String, Nothing}, line_num::Union{LineNumberNode, Int}, args...) = StaticLogRecordMetadata(source, level, string(nearest_log_level(level)), filename, line_num, args...)
StaticLogRecordMetadata(source::AbstractString, level::LogLevel, filename::Union{String, Nothing}, line_num, args...) = StaticLogRecordMetadata(source, level, string(nearest_log_level(level)), filename, line_num, args...)

StaticLogRecordMetadata(source::AbstractString, level::NamedLogLevel, args...) = StaticLogRecordMetadata(source, log_level(level), string(level), args...)

Expand Down
10 changes: 6 additions & 4 deletions test/TestLoggingCommon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module TestLoggingCommon
using LoggingCommon.Logging, LoggingCommon.Dates
using TestingUtilities, Test

@eval Main module TestModule
end
@testset "Levels" begin
@test_cases begin
input | output
Expand Down Expand Up @@ -41,10 +43,10 @@ module TestLoggingCommon
@testset "Records" begin
@testset "Utilties" begin
@test_cases begin
input | output
Main | "Main"
Main.Test | "Test"
LoggingCommon | "LoggingCommon"
input | output
Main | "Main"
Main.TestModule | "TestModule"
LoggingCommon | "LoggingCommon"
@test LoggingCommon.module_str_trim_main(input) == output
end
end
Expand Down

0 comments on commit 417f002

Please sign in to comment.