Liking cljdoc? Tell your friends :D

clojure.tools.logging.test

Extensible support for testing whether logging calls are made.

Usage example: (with-log (log/info "Hello World!") (log/error (Exception. "Did a thing") "Error: oops") (prn (logged? ns :info #"Hello")) ; true (prn (logged? ns :error [Throwable #"thing"] #"Error:")) ; true (prn (logged? ns :debug "Hi"))) ; false

Extension example, testing custom message types: (defrecord ContextualMessage [text context])

(defmethod match-message? [[String Map] ContextualMessage] [[expected-text expected-context] actual] (and (= expected-text (:text actual)) (= expected-context (-> actual :context (select-keys (keys expected-context))))))

(with-log (log/log :debug (->ContextualMessage "stuff" {:a 1 :b 2})) (prn (logged? ns :debug ["stuff" {:a 1}])) ; true (prn (logged? ns :debug ["stuff" {:a 1 :b 2}])) ; true (prn (logged? ns :debug ["stuff" {:a 1 :c 3}]))) ; false

Extensible support for testing whether logging calls are made.

Usage example:
  (with-log
    (log/info "Hello World!")
    (log/error (Exception. "Did a thing") "Error: oops")
    (prn (logged? *ns* :info #"Hello"))                                ; true
    (prn (logged? *ns* :error [Throwable #"thing"] #"Error:"))       ; true
    (prn (logged? *ns* :debug "Hi")))                                  ; false


Extension example, testing custom message types:
  (defrecord ContextualMessage [text context])

  (defmethod match-message? [[String Map] ContextualMessage]
    [[expected-text expected-context] actual]
    (and (= expected-text (:text actual))
         (= expected-context (-> actual :context (select-keys (keys expected-context))))))

  (with-log
    (log/log :debug (->ContextualMessage "stuff" {:a 1 :b 2}))
    (prn (logged? *ns* :debug ["stuff" {:a 1}]))                   ; true
    (prn (logged? *ns* :debug ["stuff" {:a 1 :b 2}]))              ; true
    (prn (logged? *ns* :debug ["stuff" {:a 1 :c 3}])))             ; false
raw docstring

*inspectable-log*clj

An instance of InspectableLog. By default unbound. See with-log, logged?, and the-log.

An instance of InspectableLog. By default unbound.
See with-log, logged?, and the-log.
sourceraw docstring

InspectableLogcljprotocol

has-match?clj

(has-match? this logger-ns level message)
(has-match? this logger-ns level throwable message)

Returns true if this log contains a matching log entry.

Returns true if this log contains a matching log entry.

has-matches?clj

(has-matches? this match-params)

Returns true if this log contains a matching log entries, in order.

Returns true if this log contains a matching log entries, in order.

stateclj

(state this)
source

logged-all?clj

(logged-all? logged-params)

Returns true if the log has log entries that match the specified params and in the same order. Must be invoked within a context in which inspectable-log is bound to an instance of InspectableLog (e.g., inside with-log)

Returns true if the log has log entries that match the specified params and
in the same order. Must be invoked within a context in which *inspectable-log*
is bound to an instance of InspectableLog (e.g., inside with-log)
sourceraw docstring

logged?clj

(logged? logger-ns level message)
(logged? logger-ns level throwable message)

Returns true if the log has a log entry that matches the specified params. Must be invoked within a context in which inspectable-log is bound to an instance of InspectableLog (e.g., inside with-log).

Default matching support: logger-ns: namespace, symbol, string level: keyword, set of keywords throwable: throwable, class, [class message-string], [class message-regex] message: string, regex

To support additional matching styles for each param, provide new methods to the respective match-*? multifn.

Returns true if the log has a log entry that matches the specified params.
Must be invoked within a context in which *inspectable-log* is bound to an
instance of InspectableLog (e.g., inside with-log).

Default matching support:
  logger-ns: namespace, symbol, string
  level:     keyword, set of keywords
  throwable: throwable, class, [class message-string], [class message-regex]
  message:   string, regex

To support additional matching styles for each param, provide new methods to
the respective match-*? multifn.
sourceraw docstring

logger-factoryclj

(logger-factory)

Returns a LoggerFactory that internally stores each logging call as a LogEntry, and satisfies the InspectableLog protocol.

See with-log.

Returns a LoggerFactory that internally stores each logging call as a
LogEntry, and satisfies the InspectableLog protocol.

See with-log.
sourceraw docstring

match-level?cljmultimethod

Returns true if expected matches the actual level. Dispatches on the (possibly-nested) types of expected and actual.

Returns true if expected matches the actual level.
Dispatches on the (possibly-nested) types of expected and actual.
sourceraw docstring

match-logger-ns?cljmultimethod

Returns true if expected matches the actual namespace. Dispatches on the (possibly-nested) types of expected and actual.

Returns true if expected matches the actual namespace.
Dispatches on the (possibly-nested) types of expected and actual.
sourceraw docstring

match-message?cljmultimethod

Returns true if expected matches the actual message. Dispatches on the (possibly-nested) types of expected and actual.

Returns true if expected matches the actual message.
Dispatches on the (possibly-nested) types of expected and actual.
sourceraw docstring

match-throwable?cljmultimethod

Returns true if expected matches the actual throwable. Dispatches on the (possibly-nested) types of expected and actual.

Returns true if expected matches the actual throwable.
Dispatches on the (possibly-nested) types of expected and actual.
sourceraw docstring

Matchercljprotocol

match?clj

(match? log-entry logger-ns level message)
(match? log-entry logger-ns level throwable message)

Returns true if the log-entry fields match the respective param.

Returns true if the log-entry fields match the respective param.
source

the-logclj

(the-log)

Returns the state of the log. Must be invoked within a context in which inspectable-log is bound to an instance of InspectableLog (e.g., inside with-log).

This may be useful when trying to determine why a call to logged? does not yield the expected result.

Returns the state of the log. Must be invoked within a context in which
*inspectable-log* is bound to an instance of InspectableLog (e.g., inside
with-log).

This may be useful when trying to determine why a call to logged? does not
yield the expected result.
sourceraw docstring

with-logcljmacro

(with-log & body)

Evaluates body within a context in which logging is collected and available via inspectable-log, allowing use of logged?, logged-all?, and the-log.

Evaluates body within a context in which logging is collected and available
via *inspectable-log*, allowing use of logged?, logged-all?, and the-log.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close