Open bamboospirit opened 6 years ago
Hi, sorry for the delay.
I don't get how you're using Clack, however, generally Clack server access logs are written by Lack.Middleware.Accesslog.
It can be configured through builder
for the app and not the scope of Clack, abstraction layer for web servers.
Is there a way to make access log write to a file?
I've looked at the AccessLog
middleware but I wasn't really able to figure that out.
Here is the full example how to do what you want, @mdbergmann:
;; Here is the systems we need
POFTHEDAY> (ql:quickload '(:lack-middleware-accesslog :clack :dexador :log4cl))
;; First, we need to configure a log4cl to log into the access.log
;; rotated on a daily basis:
POFTHEDAY> (log:config :debug :daily "access.log")
;; Now we'll create a simple app
POFTHEDAY> (defparameter *app*
(lambda (env)
'(200 (:content-type "text/plain")
("Hello, World"))))
;; And wrap it into the middleware.
;; Here we pass a :logger to redefine
;; it to use log4cl instead of writing log to the *standard-output*.
POFTHEDAY> (defparameter *app-with-access-log*
(funcall lack.middleware.accesslog:*lack-middleware-accesslog*
,*app*
:logger (lambda (message)
(log:info message))))
;; Now it's time to start our app
POFTHEDAY> (clack:clackup *app-with-access-log*
:server :woo)
Woo server is started.
Listening on 127.0.0.1:5000.
;; And to make a test request
POFTHEDAY> (values (dex:get "http://localhost:5000/"))
"Hello, World"
;; Here what it wrote into the file
POFTHEDAY> (alexandria:read-file-into-string
"access.log")
" <INFO> [13:15:11] poftheday () -
POFTHEDAY::MESSAGE: \"127.0.0.1 - [19/Jun/2020:13:15:11 +03:00] \\\"GET / HTTP/1.1\\\" 200 12 \\\"-\\\" \\\"Dexador/0.9.14 (SBCL 2.0.2); Darwin; 19.5.0\\\"\"
"
Thanks a lot. I think it would be good to have this part of the readme. For me a s a beginner of CL it's not so obvious how this works.
Hello ! In order to be able to configure the logs and error template locations I had to edit this file: clack/src/handler/hunchentoot.lisp and apply this fix: