net.lewisship.trace

Light-weight, asynchronous logging built around clojure.core/tap>.

Follows the same pattern as clojure.core/assert: When tracing is not compiled, the tracing macros should create no runtime overhead.

When tracing is compiled, a check occurs to see if tracing is enabled; only then do the most expensive operations (e.g., identifying the function containing the trace call) occur, as well as the call to clojure.core/tap>.

*compile-trace*

dynamic

If false (the default), calls to trace evaluate to nil (and trace> and trace>> simply return the threaded value).

*enable-trace*

dynamic

If false (the default is true) then compiled calls to trace (and trace> and trace>>) are a no-op.

set-compile-trace!

(set-compile-trace! value)

Sets the default value of the *compile-trace* var.

Remember that after changing this, it may be necessary to re-load namespaces for the change to take effect.

set-enable-trace!

(set-enable-trace! value)

Sets the default value of the *enable-trace* var.

Changes take effect immediately.

setup-default

(setup-default)

Enables tracing output with a default tap of pprint.

trace

macro

(trace & kvs)

Calls to trace generate a map that is passed to tap>.

The map includes keys:

  • :in - a symbol of the namespace and function
  • :line - the line number of the trace invocation (if available)
  • :thread - the string name of the current thread

Additional keys and values may be supplied.

trace expands to nil, if compilation is disabled.

Any invocation of trace evaluates to nil.

trace>

macro

(trace> value & kvs)

A version of trace that works inside -> thread expressions. Within the trace body, % is bound to the threaded value. When compilation is disabled, it simply evaluates to the threaded value.

trace>>

macro

(trace>> & kvs-then-value)

A version of trace that works inside ->> thread expressions. Within the trace body, % is bound to the threaded value. When compilation is disabled, it simply evaluates to the threaded value.