[bknr-cvs] hans changed trunk/thirdparty/hunchentoot/
BKNR Commits
bknr at bknr.net
Tue Mar 15 05:36:47 UTC 2011
Revision: 4660
Author: hans
URL: http://bknr.net/trac/changeset/4660
Improve standard logging facility by allowing log destinations to be
set to a pathname, an open stream or to NIL to suppress logging.
U trunk/thirdparty/hunchentoot/acceptor.lisp
U trunk/thirdparty/hunchentoot/doc/index.xml
U trunk/thirdparty/hunchentoot/log.lisp
U trunk/thirdparty/hunchentoot/packages.lisp
Modified: trunk/thirdparty/hunchentoot/acceptor.lisp
===================================================================
--- trunk/thirdparty/hunchentoot/acceptor.lisp 2011-03-09 18:15:44 UTC (rev 4659)
+++ trunk/thirdparty/hunchentoot/acceptor.lisp 2011-03-15 05:36:46 UTC (rev 4660)
@@ -131,17 +131,20 @@
:accessor acceptor-shutdown-lock
:documentation "The lock protecting the shutdown-queue
condition variable and the requests-in-progress counter.")
- (access-log-pathname :initarg :access-log-pathname
- :accessor acceptor-access-log-pathname
- :documentation "Pathname of the access log
-file which contains one log entry per request handled in a format
- similar to Apache's access.log.")
- (message-log-pathname :initarg :message-log-pathname
- :accessor acceptor-message-log-pathname
- :documentation "Pathname of the server error
-log file which is used to log informational,
-warning and error messages in a free-text
-format intended for human inspection")
+ (access-log-destination :initarg :access-log-destination
+ :accessor acceptor-access-log-destination
+ :documentation "Destination of the access log
+which contains one log entry per request handled in a format similar
+to Apache's access.log. Can be set to a pathname or string
+designating the log file, to a open output stream or to NIL to
+suppress logging.")
+ (message-log-destination :initarg :message-log-destination
+ :accessor acceptor-message-log-destination
+ :documentation "Destination of the server
+error log which is used to log informational, warning and error
+messages in a free-text format intended for human inspection. Can be
+set to a pathname or string designating the log file, to a open output
+stream or to NIL to suppress logging.")
(error-template-directory :initarg :error-template-directory
:accessor acceptor-error-template-directory
:documentation "Directory pathname that
@@ -168,8 +171,8 @@
:persistent-connections-p t
:read-timeout *default-connection-timeout*
:write-timeout *default-connection-timeout*
- :access-log-pathname nil
- :message-log-pathname nil
+ :access-log-destination *error-output*
+ :message-log-destination *error-output*
:document-root (load-time-value (default-document-directory))
:error-template-directory (load-time-value (default-document-directory "errors/")))
(:documentation "To create a Hunchentoot webserver, you make an
@@ -399,11 +402,11 @@
(defmethod acceptor-log-access ((acceptor acceptor) &key return-code)
"Default method for access logging. It logs the information to the
-file determined by (ACCEPTOR-ACCESS-LOG-PATHNAME ACCEPTOR) \(unless
-that value is NIL) in a format that can be parsed by most Apache log
-analysis tools.)"
+destination determined by (ACCEPTOR-ACCESS-LOG-DESTINATION ACCEPTOR)
+\(unless that value is NIL) in a format that can be parsed by most
+Apache log analysis tools.)"
- (with-open-file-or-console (stream (acceptor-access-log-pathname acceptor) *access-log-lock*)
+ (with-log-stream (stream (acceptor-access-log-destination acceptor) *access-log-lock*)
(format stream "~:[-~@[ (~A)~]~;~:*~A~@[ (~A)~]~] ~:[-~;~:*~A~] [~A] \"~A ~A~@[?~A~] ~
~A\" ~D ~:[-~;~:*~D~] \"~:[-~;~:*~A~]\" \"~:[-~;~:*~A~]\"~%"
(remote-addr*)
@@ -428,10 +431,10 @@
(defmethod acceptor-log-message ((acceptor acceptor) log-level format-string &rest format-arguments)
"Default function to log server messages. Sends a formatted message
- to the file denoted by (ACCEPTOR-MESSAGE-LOG-PATHNAME ACCEPTOR). FORMAT and
- ARGS are as in FORMAT. LOG-LEVEL is a keyword denoting the log
- level or NIL in which case it is ignored."
- (with-open-file-or-console (stream (acceptor-message-log-pathname acceptor) *message-log-lock*)
+ to the destination denoted by (ACCEPTOR-MESSAGE-LOG-DESTINATION
+ ACCEPTOR). FORMAT and ARGS are as in FORMAT. LOG-LEVEL is a
+ keyword denoting the log level or NIL in which case it is ignored."
+ (with-log-stream (stream (acceptor-message-log-destination acceptor) *message-log-lock*)
(format stream "[~A~@[ [~A]~]] ~?~%"
(iso-time) log-level
format-string format-arguments)))
Modified: trunk/thirdparty/hunchentoot/doc/index.xml
===================================================================
--- trunk/thirdparty/hunchentoot/doc/index.xml 2011-03-09 18:15:44 UTC (rev 4659)
+++ trunk/thirdparty/hunchentoot/doc/index.xml 2011-03-15 05:36:46 UTC (rev 4660)
@@ -476,7 +476,7 @@
</clix:readers>
<clix:accessors generic='true'>
- <clix:listed-accessor generic='true' name='acceptor-access-log-pathname'>
+ <clix:listed-accessor generic='true' name='acceptor-access-log-destination'>
<clix:lambda-list>acceptor
</clix:lambda-list>
<clix:returns>(or pathname null)
@@ -497,7 +497,7 @@
</clix:returns>
</clix:listed-accessor>
- <clix:listed-accessor generic='true' name='acceptor-message-log-pathname'>
+ <clix:listed-accessor generic='true' name='acceptor-message-log-destination'>
<clix:lambda-list>acceptor
</clix:lambda-list>
<clix:returns>(or pathname null)
@@ -2767,19 +2767,22 @@
</clix:subchapter>
<clix:subchapter name="logging" title="Logging">
- Hunchentoot can log accesses and diagnostic messages to two separate
- files in the file system. Logging to files is enabled and disabled by
- setting the <clix:code>ACCESS-LOG-PATHNAME</clix:code> and
- <clix:code>MESSAGE-LOG-PATHNAME</clix:code> slots in the
- <clix:ref>ACCEPTOR</clix:ref> instance of the running server, either
- by providing the :ACCESS-LOG-PATHNAME and :MESSAGE-LOG-PATHNAME
- initialization arguments when creating the acceptor or by setting the
- slots through its <clix:ref>ACCEPTOR-MESSAGE-LOG-PATHNAME</clix:ref>
- and <clix:ref>ACCEPTOR-ACCESS-LOG-PATHNAME</clix:ref> accessors.
+ Hunchentoot can log accesses and diagnostic messages to two
+ separate destinations, which can be either files in the file
+ system or streams. Logging can also be disabled by setting the
+ <clix:code>ACCESS-LOG-DESTINATION</clix:code> and
+ <clix:code>MESSAGE-LOG-DESTINATION</clix:code> slots in the
+ <clix:ref>ACCEPTOR</clix:ref> instance of the running server,
+ either by providing the :ACCESS-LOG-DESTINATION and
+ :MESSAGE-LOG-DESTINATION initialization arguments when creating the
+ acceptor or by setting the slots through its
+ <clix:ref>ACCEPTOR-MESSAGE-LOG-DESTINATION</clix:ref> and
+ <clix:ref>ACCEPTOR-ACCESS-LOG-DESTINATION</clix:ref> accessors.
<p>
- When the path for the message or accept log is set to NIL,
- hunchentoots writes corresponding log entries to the *ERROR-OUTPUT* of
- the running Lisp. This is the default.
+ When the path for the message or accept log is set to a
+ variable holding an output stream, hunchentoots writes
+ corresponding log entries to that stream. By default,
+ Hunchentoot logs to *STANDARD-ERROR*.
</p>
<p>
Access logging is done in a format similar to what
@@ -2798,9 +2801,10 @@
file format.
</p>
<p>
- Errors happening within a <a href="#handlers">handler</a> which are
- not caught by the handler itself are handled by Hunchentoot by logging
- them to the log file.
+ Errors happening within a <a href="#handlers">handler</a>
+ which are not caught by the handler itself are handled by
+ Hunchentoot by logging them to the established
+ <clix:ref>ACCEPTOR-MESSAGE-LOG-DESTINATION</clix:ref>.
</p>
<clix:function name='log-message*'>
Modified: trunk/thirdparty/hunchentoot/log.lisp
===================================================================
--- trunk/thirdparty/hunchentoot/log.lisp 2011-03-09 18:15:44 UTC (rev 4659)
+++ trunk/thirdparty/hunchentoot/log.lisp 2011-03-15 05:36:46 UTC (rev 4660)
@@ -29,30 +29,40 @@
(in-package :hunchentoot)
-(defmacro with-open-file-or-console ((stream-var pathname lock) &body body)
+(defmacro with-log-stream ((stream-var destination lock) &body body)
"Helper macro to write log entries. STREAM-VAR is a symbol that
will be bound to the logging stream during the execution of BODY.
-PATHNAME is the pathname designator of the log file or NIL if logging
-should be done to *ERROR-OUTPUT*. LOCK refers to the lock that should
-be held during the logging operation. If PATHNAME is not NIL, a flexi
-stream with UTF-8 encoding will be created and bound to STREAM-VAR.
-If an error occurs while writing to the log file, that error will be
-logged to *ERROR-OUTPUT*."
+DESTINATION is the logging destination, which can be either a pathname
+designator of the log file, a symbol designating an open stream or NIL
+if logging should be done to *ERROR-OUTPUT*. LOCK refers to the lock
+that should be held during the logging operation. If DESTINATION is a
+pathname, a flexi stream with UTF-8 encoding will be created and
+bound to STREAM-VAR. If an error occurs while writing to the log
+file, that error will be logged to *ERROR-OUTPUT*.
+
+Note that logging to a file involves opening and closing the log file
+for every logging operation, which is overall costly. Web servers
+with high throughput demands should make use of a specialized logging
+function rather than relying on Hunchentoot's default logging
+facility."
(with-unique-names (binary-stream)
- (with-rebinding (pathname)
+ (with-rebinding (destination)
(let ((body body))
- `(if ,pathname
- (with-lock-held (,lock)
- (with-open-file (,binary-stream ,pathname
- :direction :output
- :element-type 'octet
- :if-does-not-exist :create
- :if-exists :append
- #+:openmcl #+:openmcl
- :sharing :lock)
- (let ((,stream-var (make-flexi-stream ,binary-stream :external-format +utf-8+)))
- , at body)))
- (let ((,stream-var *error-output*))
- (prog1 (progn , at body)
- (finish-output *error-output*))))))))
+ `(when ,destination
+ (with-lock-held (,lock)
+ (etypecase ,destination
+ ((or string pathname)
+ (with-open-file (,binary-stream ,destination
+ :direction :output
+ :element-type 'octet
+ :if-does-not-exist :create
+ :if-exists :append
+ #+:openmcl #+:openmcl
+ :sharing :lock)
+ (let ((,stream-var (make-flexi-stream ,binary-stream :external-format +utf-8+)))
+ , at body)))
+ (stream
+ (let ((,stream-var ,destination))
+ (prog1 (progn , at body)
+ (finish-output *error-output*)))))))))))
Modified: trunk/thirdparty/hunchentoot/packages.lisp
===================================================================
--- trunk/thirdparty/hunchentoot/packages.lisp 2011-03-09 18:15:44 UTC (rev 4659)
+++ trunk/thirdparty/hunchentoot/packages.lisp 2011-03-15 05:36:46 UTC (rev 4660)
@@ -39,7 +39,6 @@
#+:lispworks
(:import-from :lw #:WITH-UNIQUE-NAMES #:WHEN-LET)
(:export #:*ACCEPTOR*
- #:*ACCESS-LOG-PATHNAME*
#:*APPROVED-RETURN-CODES*
#:*CATCH-ERRORS-P*
#+:lispworks
@@ -61,7 +60,6 @@
#:*LOG-LISP-BACKTRACES-P*
#:*LOG-LISP-ERRORS-P*
#:*LOG-LISP-WARNINGS-P*
- #:*MESSAGE-LOG-PATHNAME*
#:*METHODS-FOR-POST-PARAMETERS*
#:*REPLY*
#:*REQUEST*
@@ -121,14 +119,14 @@
#:ABORT-REQUEST-HANDLER
#:ACCEPT-CONNECTIONS
#:ACCEPTOR
- #:ACCEPTOR-ACCESS-LOG-PATHNAME
+ #:ACCEPTOR-ACCESS-LOG-DESTINATION
#:ACCEPTOR-ADDRESS
#:ACCEPTOR-DISPATCH-REQUEST
#:ACCEPTOR-ERROR-TEMPLATE-DIRECTORY
#:ACCEPTOR-INPUT-CHUNKING-P
#:ACCEPTOR-LOG-ACCESS
#:ACCEPTOR-LOG-MESSAGE
- #:ACCEPTOR-MESSAGE-LOG-PATHNAME
+ #:ACCEPTOR-MESSAGE-LOG-DESTINATION
#:ACCEPTOR-NAME
#:ACCEPTOR-OUTPUT-CHUNKING-P
#:ACCEPTOR-PERSISTENT-CONNECTIONS-P
More information about the Bknr-cvs
mailing list