Skip to content

Commit

Permalink
Merge pull request #34 from Arkoniak/33-spacekwargs
Browse files Browse the repository at this point in the history
space handling (#33)
  • Loading branch information
Arkoniak authored May 4, 2022
2 parents f11a932 + d824206 commit b4208fe
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.jl.mem
Manifest.toml
/docs/build/
extras/
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MiniLoggers"
uuid = "93f3dd0f-005d-4452-894a-a31841fa4078"
authors = ["Andrey Oskin and contributors"]
version = "0.4.2"
version = "0.4.3"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
1 change: 0 additions & 1 deletion extras/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions extras/Project.toml

This file was deleted.

3 changes: 3 additions & 0 deletions src/minilogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ function handle_message(logger::MiniLogger, level, message, _module, group, id,
printwcolor(iob, tsnow(logger.dtformat), c)
elseif val == "message"
showmessage(iob, message, logger, logger.mode)
if length(kwargs) > 0 && !isempty(message)
print(iob, " ")
end

iscomma = false
for (key, val) in kwargs
Expand Down
31 changes: 29 additions & 2 deletions test/test02_loggerformat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ conts(s, sub) = match(Regex(sub), s) !== nothing
end
end

@testset "contracting kwarg values" begin
io = IOBuffer()
logger = MiniLogger(io = io, format = "{message}")
with_logger(logger) do
@info "hello" x = 4 y = 2
s = String(take!(io))
@test s == "hello x = 4, y = 2\n"

@info "hello"
s = String(take!(io))
@test s == "hello\n"

# Due to the way message is generated, it is impossible to make it more natural
@info x = 4 y = 2
s = String(take!(io))
@test s == "4 y = 2\n"

@info "" x = 4 y = 2
s = String(take!(io))
@test s == "x = 4, y = 2\n"

@info "hello" x = 4 " and " y = 2
s = String(take!(io))
@test s == "hello x = 4 and y = 2\n"
end
end

@testset "squashing" begin
io = IOBuffer()
logger = MiniLogger(io = io, format = "{message}")
Expand Down Expand Up @@ -95,7 +122,7 @@ end
y = "asd"

with_logger(logger) do
@info "values: " x y
@info "values:" x y

s = String(take!(io))
@test s == "values: x = 1, y = asd\n"
Expand All @@ -119,7 +146,7 @@ end
try
error("ERROR")
catch err
@error "foo " exception = (err, catch_backtrace())
@error "foo" exception = (err, catch_backtrace())
end

s = String(take!(io))
Expand Down

2 comments on commit b4208fe

@Arkoniak
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/59651

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.3 -m "<description of version>" b4208fed51b4c1e9cd91407f3d6ce04d89a702b1
git push origin v0.4.3

Please sign in to comment.