From ece762fc5b9b4632674cc1b86c50a3a1ecca4423 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 4 Oct 2022 21:13:07 +1300 Subject: [PATCH] Unify "out: " logging to a function --- src/config.rkt | 1 + src/data.rkt | 2 +- src/page-category.rkt | 4 ++-- src/page-search.rkt | 2 +- src/page-wiki.rkt | 2 +- src/url-utils.rkt | 10 +++++++++- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/config.rkt b/src/config.rkt index bdf4440..4c8fca9 100644 --- a/src/config.rkt +++ b/src/config.rkt @@ -26,6 +26,7 @@ (canonical_origin . "") (debug . "false") (instance_is_official . "false") ; please don't turn this on, or you will make me very upset + (log_outgoing . "true") (port . "10416") (strict_proxy . "true"))) diff --git a/src/data.rkt b/src/data.rkt index f7a0d1f..8eb0cd6 100644 --- a/src/data.rkt +++ b/src/data.rkt @@ -20,7 +20,7 @@ ("siprop" . "rightsinfo") ("format" . "json") ("formatversion" . "2"))))) - (printf "out: ~a~n" dest-url) + (log-outgoing dest-url) (define res (easy:get dest-url)) (define data (easy:response-json res)) (license (jp "/query/rightsinfo/text" data) diff --git a/src/page-category.rkt b/src/page-category.rkt index f9eb974..f7c43b2 100644 --- a/src/page-category.rkt +++ b/src/page-category.rkt @@ -75,7 +75,7 @@ ("cmlimit" . "max") ("formatversion" . "2") ("format" . "json"))))) - (printf "out: ~a~n" dest-url) + (log-outgoing dest-url) (define dest-res (easy:get dest-url #:timeouts timeouts)) (easy:response-json dest-res)] [page-data (define dest-url @@ -86,7 +86,7 @@ ("prop" . "text|headhtml|langlinks") ("formatversion" . "2") ("format" . "json"))))) - (printf "out: ~a~n" dest-url) + (log-outgoing dest-url) (define dest-res (easy:get dest-url #:timeouts timeouts)) (easy:response-json dest-res)] [license (license-auto wikiname)]) diff --git a/src/page-search.rkt b/src/page-search.rkt index 61b1212..387deab 100644 --- a/src/page-search.rkt +++ b/src/page-search.rkt @@ -68,7 +68,7 @@ ("format" . "json"))))) (thread-let - ([dest-res (printf "out: ~a~n" dest-url) + ([dest-res (log-outgoing dest-url) (easy:get dest-url #:timeouts timeouts)] [license (license-auto wikiname)]) diff --git a/src/page-wiki.rkt b/src/page-wiki.rkt index 96410d0..461594a 100644 --- a/src/page-wiki.rkt +++ b/src/page-wiki.rkt @@ -246,7 +246,7 @@ ("prop" . "text|headhtml|langlinks") ("formatversion" . "2") ("format" . "json"))))) - (printf "out: ~a~n" dest-url) + (log-outgoing dest-url) (easy:get dest-url #:timeouts timeouts)] [license (license-auto wikiname)]) diff --git a/src/url-utils.rkt b/src/url-utils.rkt index 934a228..20b9b42 100644 --- a/src/url-utils.rkt +++ b/src/url-utils.rkt @@ -1,6 +1,7 @@ #lang typed/racket/base (require racket/string "pure-utils.rkt") +(require/typed "config.rkt" [config-true? (Symbol -> Boolean)]) (provide ; make a query string from an association list of strings @@ -8,7 +9,9 @@ ; make a proxied version of a fandom url u-proxy-url ; check whether a url is on a domain controlled by fandom - is-fandom-url?) + is-fandom-url? + ; prints "out: " + log-outgoing) (module+ test (require "typed-rackunit.rkt")) @@ -69,3 +72,8 @@ is-fandom-url? (λ ([v : String]) (string-append "/proxy?" (params->query `(("dest" . ,url))))) url)) + +(: log-outgoing (String -> Void)) +(define (log-outgoing url-string) + (when (config-true? 'log_outgoing) + (printf "out: ~a~n" url-string)))