fukamachi / clack

Web server abstraction layer for Common Lisp
MIT License
1.04k stars 86 forks source link

access-log-destination can't be configured #147

Open bamboospirit opened 6 years ago

bamboospirit commented 6 years ago

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:

(defun run (app &rest args
            &key debug (port 5000)
              ssl ssl-key-file ssl-cert-file ssl-key-password
              access-log-destination error-template-directory message-log-destination ; <- ADDED
              max-thread-count max-accept-count (persistent-connections-p t))
;    then added these 3 params in the two  (apply #'make-instance...) below
fukamachi commented 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.

mdbergmann commented 4 years ago

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.

svetlyak40wt commented 4 years ago

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\\\"\"

"
mdbergmann commented 4 years ago

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.