Skip to content

Commit e57075c

Browse files
authored
Merge pull request #141 from sig-gis/HER-648-pnguyen-truncate-request-config
Truncate request config
2 parents e7717bd + b91d70c commit e57075c

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

README.org

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ file logging system, and worker functions for non-HTTP-related tasks.
6767
:cider-nrepl true ; If your editor supports CIDER middleware
6868
:mode "dev" ; or prod
6969
:log-dir "logs" ; or "" for stdout
70+
:truncate-request? false ; true by default
7071
:handler product-ns.routing/handler
7172
:workers {:scheduler {:start product-ns.jobs/start-scheduled-jobs!
7273
:stop product-ns.jobs/stop-scheduled-jobs!}}

src/triangulum/config.clj

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
(s/def ::url-or-file-path (s/and string? #(re-matches #"^(https?:\/\/[^\s\/$.?#].[^\s]*)|(/[^:*?\"<>|]*)$" %)))
2525
(s/def ::path (s/and string? #(re-matches #"[./][^:*?\"<>|]*" %)))
2626
(s/def ::hostname (s/and string? #(re-matches #"[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" %)))
27+
(s/def ::boolean boolean?)
2728

2829
;; Config file
2930

src/triangulum/handler.clj

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
wrap-frame-options
2424
wrap-xss-protection]]
2525
[triangulum.config :as config :refer [get-config]]
26-
[triangulum.logging :refer [log-str]]
26+
[triangulum.logging :refer [log log-str]]
2727
[triangulum.errors :refer [nil-on-error]]
2828
[triangulum.utils :refer [resolve-foreign-symbol]]
2929
[triangulum.response :refer [forbidden-response data-response]]))
@@ -87,8 +87,11 @@
8787
(let [{:keys [uri request-method params]} request
8888
private-request-keys (or (get-config :server :private-request-keys)
8989
#{:password :passwordConfirmation})
90+
truncate-request? (if (some? (get-config :server :truncate-request?))
91+
(get-config :server :truncate-request?)
92+
true)
9093
param-str (pr-str (apply dissoc params private-request-keys))]
91-
(log-str "Request(" (name request-method) "): \"" uri "\" " param-str)
94+
(log (apply str "Request(" (name request-method) "): \"" uri "\" " param-str) :truncate? truncate-request?)
9295
(handler request))))
9396

9497
(defn wrap-response-logging

src/triangulum/logging.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"Synchronously create a log entry. Logs will got to standard out as default.
3434
A log file location can be specified with set-log-path!.
3535
36-
Default options are {:newline? true :pprint? false :force-stdout? false}"
36+
Default options are {:newline? true :pprint? false :force-stdout? false truncate? true}"
3737
[data & {:keys [newline? pprint? force-stdout? truncate?]
3838
:or {newline? true pprint? false force-stdout? false truncate? true}}]
3939
(let [timestamp (.format (SimpleDateFormat. "MM/dd HH:mm:ss") (Date.))

src/triangulum/server.clj

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
(s/def ::cider-nrepl boolean?)
2626
(s/def ::mode (s/and ::config/string #{"dev" "prod"}))
2727
(s/def ::log-dir ::config/string)
28+
(s/def ::truncate-request? ::config/boolean)
2829
(s/def ::handler ::config/namespaced-symbol)
2930
(s/def ::keystore-file ::config/string)
3031
(s/def ::keystore-type ::config/string)
@@ -44,13 +45,14 @@
4445
(defn start-server!
4546
"See README.org -> Web Framework -> triangulum.server for details."
4647
[{:keys [http-port https-port nrepl cider-nrepl nrepl-bind nrepl-port mode log-dir
47-
handler workers keystore-file keystore-type keystore-password]
48+
truncate-request? handler workers keystore-file keystore-type keystore-password]
4849
:or {nrepl-bind "127.0.0.1"
4950
nrepl-port 5555
5051
keystore-file "./.key/keystore.pkcs12"
5152
keystore-type "pkcs12"
5253
keystore-password "foobar"
5354
log-dir ""
55+
truncate-request? true
5456
mode "prod"}}]
5557
(let [has-key? (and keystore-file (.exists (io/file keystore-file)))
5658
ssl? (and has-key? https-port)
@@ -59,7 +61,8 @@
5961
(create-handler-stack ssl? reload?))
6062
config (merge
6163
{:port http-port
62-
:join? false}
64+
:join? false
65+
:truncate-request? truncate-request?}
6366
(when ssl?
6467
{:ssl? true
6568
:ssl-port https-port

0 commit comments

Comments
 (0)