Skip to content

Commit

Permalink
cleaning up loggingextras (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart authored Jul 24, 2023
1 parent 3e727f7 commit 9c4f0f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name = "LiveServer"
uuid = "16fef848-5104-11e9-1b77-fb7a48bbb589"
authors = ["Jonas Asprion <[email protected]", "Thibaut Lienart <[email protected]>"]
version = "1.2.6"
version = "1.2.7"

[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand All @@ -13,4 +14,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[compat]
HTTP = "1"
MIMEs = "0.1"
LoggingExtras = "1"
julia = "1.6"
1 change: 1 addition & 0 deletions src/LiveServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Base.Filesystem
using Base.Threads: @spawn

using HTTP
using LoggingExtras

export serve, servedocs

Expand Down
19 changes: 16 additions & 3 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function update_and_close_viewers!(
@sync for wsᵢ in ws_to_update_and_close
isopen(wsᵢ.io) && @spawn begin
try
redirect_stderr()
HTTP.WebSockets.send(wsᵢ, "update")
catch
end
Expand All @@ -64,7 +63,6 @@ function update_and_close_viewers!(
@sync for wsi in ws_to_update_and_close
isopen(wsi.io) && @spawn begin
try
redirect_stderr()
wsi.writeclosed = wsi.readclosed = true
close(wsi.io)
catch
Expand Down Expand Up @@ -618,6 +616,15 @@ current directory. (See also [`example`](@ref) for an example folder).
)
end

old_logger = global_logger()
old_stderr = stderr
global_logger(
EarlyFilteredLogger(
log -> log._module !== HTTP.Servers,
global_logger()
)
)

server, port = get_server(host, port, req_handler)
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
url = "http://$host_str:$port"
Expand Down Expand Up @@ -676,6 +683,13 @@ current directory. (See also [`example`](@ref) for an example folder).
reset_ws_interrupt()
println("")
end

# given that LiveServer is interrupted via an InterruptException, we have
# to be extra careful that things are back as they were before, otherwise
# there's a high risk of the disgusting broken pipe error...
redirect_stderr(old_stderr)
global_logger(old_logger)

return nothing
end

Expand All @@ -697,7 +711,6 @@ function get_server(
incr >= 10 && @error "couldn't find a free port in $incr tries"
try
server = HTTP.listen!(host, port; readtimeout=0, verbose=-1) do http::HTTP.Stream
redirect_stderr()
if HTTP.WebSockets.isupgrade(http.message)
# upgrade to websocket and add to list of viewers and keep open
# until written to
Expand Down

2 comments on commit 9c4f0f1

@tlienart
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/88168

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 v1.2.7 -m "<description of version>" 9c4f0f18d8e023293ef78915609f707d48027dc0
git push origin v1.2.7

Please sign in to comment.