After using Hunchentoot as my HTTP server for a while I decided to switch to Clack. One of the first things I needed to do was to enable access logging. This stumped me for a while because it is not as trivial as with Hunchentoot. After digging around I found the relevant documentation.
By default Clack does not log anything. It is distributed with the
<clack-middleware-accesslog>
middleware which can log HTTP accesses but
must be explicitly enabled.
Without any customization the code below will log to *standard-output*
.
(clack:clackup
(builder
(clack.middleware.accesslog:<clack-middleware-accesslog>))
#'app)
The middleware provides three methods for customization.
-
*time-format*
A variable to change the format used to display time. -
formatter
A slot which takes a function of three parameters. It returns the formatted string which will be logged.The function prototype is:
(defun formatter (clack-env http-result-code current-time))
-
logger
A slot which takes a function of one parameter. The parameter is the string to be logged. This function performs the actual logging action.
One possible customization is this:
(clack:clackup
(builder
(clack.middleware.accesslog:<clack-middleware-accesslog>
:logger #'model:http-access-log))
#'app)