Access log, stats and errors
Access log
:access-log takes a fn that's called once for every response plumeria writes, its own rejects (400, 408, 413, 431, 505) included, with an entry map: :request-method :uri :query-string :protocol :status :bytes :duration-ms :remote-addr :user-agent :referer :time-ms, plus :websocket? for a 101 (logged when the upgrade is answered). :bytes is what went out, head included (plaintext bytes under TLS). For a request line that didn't parse, the method, URI and protocol are nil.
(require '[plumeria.log :as log])
(http/run-server handler {:port 18090 :access-log log/print-log})
;; 127.0.0.1 - - [08/Nov/2026:01:02:03 +0000] "GET /a?x=1 HTTP/1.1" 200 59 "-" "curl/8.7.1"
log/print-log writes NCSA combined lines from one agent, so lines never interleave and a connection never waits on stdout. log/common-log-line is the formatter on its own. Values are escaped the way Apache escapes them (\\, \", control bytes as \xhh), so a client can't forge a line. Your own fn runs on the connection's fiber, so like a handler it must not block, and one that throws is ignored.
Stats
(http/server-stats handle) answers {:connections :websockets :requests :responses {:1xx :2xx :3xx :4xx :5xx}}. The first two are open now, and the rest count every response since the server started.
Errors
When something fails that the client didn't cause, the server still answers as it would anyway (a 500, or a closed connection), and it also hands an event map to :on-error:
:type | When |
|---|---|
:handler-threw | the handler threw (or an async handler raised); the client got a 500 |
:render-failed | the response map couldn't be rendered (500) |
:stream-threw | a :stream fn, seq or InputStream body threw partway |
:file-failed | a File body couldn't be opened or read |
:header-dropped | a response header was refused as unsafe |
:write-timeout | the reaper closed a write that ran past :write-ms |
:accept-failed | an accept failed and the loop is backing off |
:connection-threw | something unexpected ended a connection's loop |
:async-timeout | an async handler didn't answer within :async-timeout-ms |
:handler-timeout | a sync handler ran past :handler-ms and was killed; the client got a 503. Has :request and :handler-ms |
:websocket-threw | a websocket listener callback threw |
:tls-handshake-failed, :tls-reload-failed, :tls-reload-disabled | see https.md |
:acme-issued | a certificate was issued and is now serving; has :domains and :not-after |
:acme-failed | an order failed and will be retried; has :step, :problem, :not-after, :retry-in-ms and sometimes :hint |
:acme-no-certificate | at start, no usable certificate was on disk; has :reason |
The ACME events (see https.md) carry their own fields. :acme-issued has :domains (a vector of names) and :not-after (a java.util.Date). :acme-failed has :step, the point in the order that failed (:directory, :nonce, :account, :order, :authorization, :finalize, :certificate, or :http and :unexpected for a failure outside the CA's answers). :problem is a map with the CA's "type" and "detail", or plumeria's own plumeria:error and plumeria:unexpected types. :not-after is when the certificate still serving expires, nil when there is none, :retry-in-ms is the wait before the next attempt, and :hint appears after an invalid authorization and says to check that each name resolves to this host and that port 80 is reachable. :acme-no-certificate's :reason is :missing, :bad-pair (the key and certificate don't match) or :expired. The default hook prints them as one line, for example plumeria: acme-failed authorization: urn:ietf:params:acme:error:connection ..., retry in 900000 ms. No ACME event ever carries a private key.
Events carry :throwable, :request, :file, :header, :remote-addr or :backoff-ms as they apply. :header is the name only, since a refused value can hold anything. Malformed requests, size limits, timeouts and peers that hang up are routine, so they aren't reported.
The default, plumeria.core/default-on-error, prints one line to stderr (a :handler-timeout line ends with after N ms), and (fn [_]) turns reporting off. The hook runs on the connection's fiber, so it must not block, and a hook that throws is ignored.