diff --git a/collects/web-server/configuration.ss b/collects/web-server/configuration.ss index 47a1abb343..e9d021659f 100644 --- a/collects/web-server/configuration.ss +++ b/collects/web-server/configuration.ss @@ -246,23 +246,25 @@ ; to produce a string that is displayed into the log file (define (gen-log-message log-format log-path) (let ([outsem (make-semaphore 1)] - [log-p #f]) + [log-p (make-parameter #f)]) (lambda (host-ip client-ip method uri host) - (semaphore-wait outsem) - (unless (and log-p (file-exists? log-path)) - (when log-p - (close-output-port log-p)) - (set! log-p (open-output-file log-path 'append)) - (file-stream-buffer-mode log-p 'line)) - ; do the display all at once by formating first - (when log-p - (display - (format "~s~n" - (list 'from client-ip 'to host-ip 'for (url->string uri) 'at - (date->string (seconds->date (current-seconds)) #t))) - log-p)) - (semaphore-post outsem)))) - + (call-with-semaphore + outsem + (lambda () + (with-handlers ([exn? (lambda (e) (log-p #f))]) + (unless (and (log-p) (file-exists? log-path)) + (unless (eq? (log-p) #f) + (close-output-port (log-p))) + (log-p (open-output-file log-path 'append)) + (file-stream-buffer-mode (log-p) 'line)) + ; do the display all at once by formating first + (when (log-p) + (display + (format "~s~n" + (list 'from client-ip 'to host-ip 'for (url->string uri) 'at + (date->string (seconds->date (current-seconds)) #t))) + (log-p))))))))) + ; ignore-log : sym str -> str str sym url str -> str (define (ignore-log log-format log-path) void)