@@ -606,72 +606,86 @@ current directory. (See also [`example`](@ref) for an example folder).
606
606
# starts the file watcher
607
607
start (fw)
608
608
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
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)"
616
629
)
617
- end
618
630
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 ())
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 )
635
655
end
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 ())
656
+ catch err
657
+ if ! isa (err, InterruptException)
658
+ if VERBOSE[]
659
+ @error " serve error" exception= (err, catch_backtrace ())
660
+ end
661
+ throw (err)
647
662
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
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
663
677
end
664
678
end
665
679
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 (" ✓" )
666
688
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 (" ✓" )
675
689
end
676
690
return nothing
677
691
end
0 commit comments