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
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.
(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? 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.
(state this)
(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)
(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.
(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.
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.
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.
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.
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.
(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.
(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.
(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.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close