Skip to content

Commit

Permalink
rolling back agressive logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Jul 17, 2023
2 parents 8282a29 + 454e63c commit 282beb5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LiveServer"
uuid = "16fef848-5104-11e9-1b77-fb7a48bbb589"
authors = ["Jonas Asprion <[email protected]", "Thibaut Lienart <[email protected]>"]
version = "1.2.3"
version = "1.2.4"

[deps]
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Expand Down
130 changes: 58 additions & 72 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,86 +606,72 @@ current directory. (See also [`example`](@ref) for an example folder).
# starts the file watcher
start(fw)

# HTTP uses LoggingExtras and, in particular, a @logmsgv which is very
# annoying for LiveServer, see https://github.com/JuliaWeb/HTTP.jl/issues/938
# as a result we just capture all the logging and discard everything
Base.CoreLogging.with_logger(TestLogger()) do

# make request handler
req_handler = HTTP.Handlers.streamhandler() do req
req = preprocess_request(req)
serve_file(
fw, req;
inject_browser_reload_script = inject_browser_reload_script,
allow_cors = allow_cors
)
end

server, port = get_server(host, port, req_handler)
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
url = "http://$host_str:$port"
println(
"✓ LiveServer listening on $url/ ...\n (use CTRL+C to shut down)"
# make request handler
req_handler = HTTP.Handlers.streamhandler() do req
req = preprocess_request(req)
serve_file(
fw, req;
inject_browser_reload_script = inject_browser_reload_script,
allow_cors = allow_cors
)
end

launch_browser && open_in_default_browser(url)
# wait until user interrupts the LiveServer (using CTRL+C).
try
counter = 1
while true
if WS_INTERRUPT[] || fw.status == :interrupted
# rethrow the interruption (which may have happened during
# the websocket handling or during the file watching)
throw(InterruptException())
end

sleep(2)
try
sqrt(-1)
catch e
HTTP.LoggingExtras.@logmsgv 1 HTTP.Logging.Error "I don't want to see this" exception=(e, stacktrace(catch_backtrace()))
end

# run the auxiliary function if there is one (by default this does
# nothing)
coreloopfun(counter, fw)
# update the cycle counter and sleep (yields to other threads)
counter += 1
sleep(0.1)
server, port = get_server(host, port, req_handler)
host_str = ifelse(host == string(Sockets.localhost), "localhost", host)
url = "http://$host_str:$port"
println(
"✓ LiveServer listening on $url/ ...\n (use CTRL+C to shut down)"
)

launch_browser && open_in_default_browser(url)
# wait until user interrupts the LiveServer (using CTRL+C).
try
counter = 1
while true
if WS_INTERRUPT[] || fw.status == :interrupted
# rethrow the interruption (which may have happened during
# the websocket handling or during the file watching)
throw(InterruptException())
end
catch err
if !isa(err, InterruptException)
if VERBOSE[]
@error "serve error" exception=(err, catch_backtrace())
end
throw(err)
# run the auxiliary function if there is one (by default this does
# nothing)
coreloopfun(counter, fw)
# update the cycle counter and sleep (yields to other threads)
counter += 1
sleep(0.1)
end
catch err
if !isa(err, InterruptException)
if VERBOSE[]
@error "serve error" exception=(err, catch_backtrace())
end
finally
# cleanup: close everything that might still be alive
print("\n⋮ shutting down LiveServer… ")
# stop the filewatcher
stop(fw)
# close any remaining websockets
for wss values(WS_VIEWERS)
@sync for wsi in wss
isopen(wsi.io) && @async begin
try
wsi.writeclosed = wsi.readclosed = true
close(wsi.io)
catch
end
throw(err)
end
finally
# cleanup: close everything that might still be alive
print("\n⋮ shutting down LiveServer… ")
# stop the filewatcher
stop(fw)
# close any remaining websockets
for wss values(WS_VIEWERS)
@sync for wsi in wss
isopen(wsi.io) && @async begin
try
wsi.writeclosed = wsi.readclosed = true
close(wsi.io)
catch
end
end
end
# empty the dictionary of viewers
empty!(WS_VIEWERS)
# shut down the server
HTTP.Servers.forceclose(server)
# reset other environment variables
reset_content_dir()
reset_ws_interrupt()
println("")
end
# empty the dictionary of viewers
empty!(WS_VIEWERS)
# shut down the server
HTTP.Servers.forceclose(server)
# reset other environment variables
reset_content_dir()
reset_ws_interrupt()
println("")
end
return nothing
end
Expand Down

2 comments on commit 282beb5

@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/87620

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.4 -m "<description of version>" 282beb53377da859f5c260026dcc19305e250c5b
git push origin v1.2.4

Please sign in to comment.