Skip to content

Commit 9c4f0f1

Browse files
authored
cleaning up loggingextras (#172)
1 parent 3e727f7 commit 9c4f0f1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name = "LiveServer"
22
uuid = "16fef848-5104-11e9-1b77-fb7a48bbb589"
33
authors = ["Jonas Asprion <jonas.asprion@gmx.ch", "Thibaut Lienart <tlienart@me.com>"]
4-
version = "1.2.6"
4+
version = "1.2.7"
55

66
[deps]
77
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
8+
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
89
MIMEs = "6c6e2e6c-3030-632d-7369-2d6c69616d65"
910
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1011
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
@@ -13,4 +14,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1314
[compat]
1415
HTTP = "1"
1516
MIMEs = "0.1"
17+
LoggingExtras = "1"
1618
julia = "1.6"

src/LiveServer.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Base.Filesystem
55
using Base.Threads: @spawn
66

77
using HTTP
8+
using LoggingExtras
89

910
export serve, servedocs
1011

src/server.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ function update_and_close_viewers!(
5252
@sync for wsᵢ in ws_to_update_and_close
5353
isopen(wsᵢ.io) && @spawn begin
5454
try
55-
redirect_stderr()
5655
HTTP.WebSockets.send(wsᵢ, "update")
5756
catch
5857
end
@@ -64,7 +63,6 @@ function update_and_close_viewers!(
6463
@sync for wsi in ws_to_update_and_close
6564
isopen(wsi.io) && @spawn begin
6665
try
67-
redirect_stderr()
6866
wsi.writeclosed = wsi.readclosed = true
6967
close(wsi.io)
7068
catch
@@ -618,6 +616,15 @@ current directory. (See also [`example`](@ref) for an example folder).
618616
)
619617
end
620618

619+
old_logger = global_logger()
620+
old_stderr = stderr
621+
global_logger(
622+
EarlyFilteredLogger(
623+
log -> log._module !== HTTP.Servers,
624+
global_logger()
625+
)
626+
)
627+
621628
server, port = get_server(host, port, req_handler)
622629
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
623630
url = "http://$host_str:$port"
@@ -676,6 +683,13 @@ current directory. (See also [`example`](@ref) for an example folder).
676683
reset_ws_interrupt()
677684
println("")
678685
end
686+
687+
# given that LiveServer is interrupted via an InterruptException, we have
688+
# to be extra careful that things are back as they were before, otherwise
689+
# there's a high risk of the disgusting broken pipe error...
690+
redirect_stderr(old_stderr)
691+
global_logger(old_logger)
692+
679693
return nothing
680694
end
681695

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

0 commit comments

Comments
 (0)