Skip to content

Commit 282beb5

Browse files
committed
rolling back agressive logging
2 parents 8282a29 + 454e63c commit 282beb5

File tree

2 files changed

+59
-73
lines changed

2 files changed

+59
-73
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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.3"
4+
version = "1.2.4"
55

66
[deps]
77
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"

src/server.jl

Lines changed: 58 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -606,86 +606,72 @@ current directory. (See also [`example`](@ref) for an example folder).
606606
# starts the file watcher
607607
start(fw)
608608

609-
# HTTP uses LoggingExtras and, in particular, a @logmsgv which is very
610-
# annoying for LiveServer, see https://github.com/JuliaWeb/HTTP.jl/issues/938
611-
# as a result we just capture all the logging and discard everything
612-
Base.CoreLogging.with_logger(TestLogger()) do
613-
614-
# make request handler
615-
req_handler = HTTP.Handlers.streamhandler() do req
616-
req = preprocess_request(req)
617-
serve_file(
618-
fw, req;
619-
inject_browser_reload_script = inject_browser_reload_script,
620-
allow_cors = allow_cors
621-
)
622-
end
623-
624-
server, port = get_server(host, port, req_handler)
625-
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
626-
url = "http://$host_str:$port"
627-
println(
628-
"✓ LiveServer listening on $url/ ...\n (use CTRL+C to shut down)"
609+
# make request handler
610+
req_handler = HTTP.Handlers.streamhandler() do req
611+
req = preprocess_request(req)
612+
serve_file(
613+
fw, req;
614+
inject_browser_reload_script = inject_browser_reload_script,
615+
allow_cors = allow_cors
629616
)
617+
end
630618

631-
launch_browser && open_in_default_browser(url)
632-
# wait until user interrupts the LiveServer (using CTRL+C).
633-
try
634-
counter = 1
635-
while true
636-
if WS_INTERRUPT[] || fw.status == :interrupted
637-
# rethrow the interruption (which may have happened during
638-
# the websocket handling or during the file watching)
639-
throw(InterruptException())
640-
end
641-
642-
sleep(2)
643-
try
644-
sqrt(-1)
645-
catch e
646-
HTTP.LoggingExtras.@logmsgv 1 HTTP.Logging.Error "I don't want to see this" exception=(e, stacktrace(catch_backtrace()))
647-
end
648-
649-
# run the auxiliary function if there is one (by default this does
650-
# nothing)
651-
coreloopfun(counter, fw)
652-
# update the cycle counter and sleep (yields to other threads)
653-
counter += 1
654-
sleep(0.1)
619+
server, port = get_server(host, port, req_handler)
620+
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
621+
url = "http://$host_str:$port"
622+
println(
623+
"✓ LiveServer listening on $url/ ...\n (use CTRL+C to shut down)"
624+
)
625+
626+
launch_browser && open_in_default_browser(url)
627+
# wait until user interrupts the LiveServer (using CTRL+C).
628+
try
629+
counter = 1
630+
while true
631+
if WS_INTERRUPT[] || fw.status == :interrupted
632+
# rethrow the interruption (which may have happened during
633+
# the websocket handling or during the file watching)
634+
throw(InterruptException())
655635
end
656-
catch err
657-
if !isa(err, InterruptException)
658-
if VERBOSE[]
659-
@error "serve error" exception=(err, catch_backtrace())
660-
end
661-
throw(err)
636+
# run the auxiliary function if there is one (by default this does
637+
# nothing)
638+
coreloopfun(counter, fw)
639+
# update the cycle counter and sleep (yields to other threads)
640+
counter += 1
641+
sleep(0.1)
642+
end
643+
catch err
644+
if !isa(err, InterruptException)
645+
if VERBOSE[]
646+
@error "serve error" exception=(err, catch_backtrace())
662647
end
663-
finally
664-
# cleanup: close everything that might still be alive
665-
print("\n⋮ shutting down LiveServer… ")
666-
# stop the filewatcher
667-
stop(fw)
668-
# close any remaining websockets
669-
for wss values(WS_VIEWERS)
670-
@sync for wsi in wss
671-
isopen(wsi.io) && @async begin
672-
try
673-
wsi.writeclosed = wsi.readclosed = true
674-
close(wsi.io)
675-
catch
676-
end
648+
throw(err)
649+
end
650+
finally
651+
# cleanup: close everything that might still be alive
652+
print("\n⋮ shutting down LiveServer… ")
653+
# stop the filewatcher
654+
stop(fw)
655+
# close any remaining websockets
656+
for wss values(WS_VIEWERS)
657+
@sync for wsi in wss
658+
isopen(wsi.io) && @async begin
659+
try
660+
wsi.writeclosed = wsi.readclosed = true
661+
close(wsi.io)
662+
catch
677663
end
678664
end
679665
end
680-
# empty the dictionary of viewers
681-
empty!(WS_VIEWERS)
682-
# shut down the server
683-
HTTP.Servers.forceclose(server)
684-
# reset other environment variables
685-
reset_content_dir()
686-
reset_ws_interrupt()
687-
println("")
688666
end
667+
# empty the dictionary of viewers
668+
empty!(WS_VIEWERS)
669+
# shut down the server
670+
HTTP.Servers.forceclose(server)
671+
# reset other environment variables
672+
reset_content_dir()
673+
reset_ws_interrupt()
674+
println("")
689675
end
690676
return nothing
691677
end

0 commit comments

Comments
 (0)