Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bamboospirit opened this issue Oct 1, 2017 · 4 comments
Open

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

bamboospirit opened this issue Oct 1, 2017 · 4 comments

Comments

@bamboospirit
Copy link

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
Copy link
Owner

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
Copy link

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
Copy link
Contributor

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants