Skip to content

Commit 6fc1f5d

Browse files
author
karei
committed
chore(release): v0.1.2
1 parent 092df53 commit 6fc1f5d

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
### Changed
3333
- Documentation: general improvements and clarifications.
3434

35+
## [0.1.2] - 2025-10-13
36+
### Changed
37+
- PlainLogger: reworked rendering for simpler, more predictable output and better performance.
38+
- Use `render_plain` helpers: arrays with `N >= 2` are shown with `show(MIME"text/plain")` for readable matrices; scalars and 1-D arrays print directly.
39+
- Remove color styling and rely on plain printing for consistent logs across environments.
40+
- Normalize metadata footer: prints `@ <Module> <file> :<line>` only when available, always followed by a newline.
41+
- Tighten `handle_message` signature to `message::Union{Tuple,AbstractString}`.
42+
- Add `@nospecialize kwargs` to avoid excessive specialization and reduce latency.
43+
44+
### Fixed
45+
- Ensure `handle_message` always returns `nothing` for type stability.
46+
3547
[Unreleased]: https://github.com/<owner>/<repo>/compare/v0.1.1...HEAD
48+
[0.1.2]: https://github.com/<owner>/<repo>/compare/v0.1.1...v0.1.2
3649
[0.1.1]: https://github.com/<owner>/<repo>/compare/v0.1.0...v0.1.1

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentLogging"
22
uuid = "3f6ec708-df3b-46b4-8b70-ec9fa53b9f7d"
33
authors = ["karei <abcdvvvv@gmail.com>"]
4-
version = "0.1.1"
4+
version = "0.1.2"
55

66
[deps]
77
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"

src/PlainLogger.jl

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ PlainLogger(min_level::LogLevel=Info) = PlainLogger(Base.CoreLogging.closed_stre
1111
Logging.min_enabled_level(logger::PlainLogger) = logger.min_level
1212
Logging.shouldlog(logger::PlainLogger, level, _module, group, id) = level >= logger.min_level
1313

14-
function Logging.handle_message(l::PlainLogger, level::LogLevel, message, _module, group, id, file, line; kwargs...)
14+
function render_plain(iob, x::AbstractArray{T,N}) where {T,N}
15+
if N >= 2
16+
show(iob, MIME"text/plain"(), x)
17+
else
18+
print(iob, x)
19+
end
20+
end
21+
22+
render_plain(iob, x) = print(iob, x)
23+
24+
function Logging.handle_message(l::PlainLogger, level::LogLevel, message::Union{Tuple,AbstractString}, _module, group, id, file, line; kwargs...)::Nothing
25+
@nospecialize kwargs
26+
1527
stream::IO = l.stream
1628
if !(isopen(stream)::Bool)
1729
stream = stderr
@@ -20,40 +32,31 @@ function Logging.handle_message(l::PlainLogger, level::LogLevel, message, _modul
2032
buf = IOBuffer()
2133
iob = IOContext(buf, stream)
2234

23-
color = level >= Error ? :red : level >= Warn ? :yellow : level == Debug ? :green : :normal
24-
pretty(x) = begin
25-
if x isa AbstractArray{T,2} where {T} || x isa AbstractArray{T,3} where {T}
26-
str = sprint(show, MIME"text/plain"(), x)
27-
printstyled(iob, str; color)
28-
else
29-
printstyled(iob, x; color)
30-
end
31-
end
32-
3335
if message isa Tuple
3436
for m in message
35-
pretty(m)
37+
render_plain(iob, m)
3638
end
3739
else
38-
pretty(message)
40+
render_plain(iob, message)
3941
end
4042
for (k, v) in kwargs
41-
print(iob, "\n ")
42-
printstyled(iob, k, " = "; color)
43-
pretty(v)
43+
print(iob, "\n ", k, " = ")
44+
render_plain(iob, v)
4445
end
4546

4647
if _module !== nothing || file !== nothing
47-
println(iob)
48-
printstyled(iob, "@ "; color)
49-
_module !== nothing && printstyled(iob, string(_module), " "; color)
50-
file !== nothing && printstyled(iob, Base.basename(String(file)), " "; color)
51-
line !== nothing && printstyled(iob, ":", line; color)
48+
print(iob, "\n@ ")
49+
_module !== nothing && print(iob, string(_module), " ")
50+
if file !== nothing
51+
print(iob, Base.basename(String(file)), " ")
52+
line !== nothing && print(iob, ":", line)
53+
end
5254
end
5355
println(iob)
5456

5557
bytes = take!(buf)
5658
lock(l.lock) do
5759
write(stream, bytes)
5860
end
61+
nothing
5962
end

0 commit comments

Comments
 (0)