A lightweight, configurable ClojureScript logging library with compile-time optimization.
A lightweight, configurable ClojureScript logging library with compile-time optimization.
Runtime support for shimmer logging library.
Runtime support for shimmer logging library.
Function (fn [namespace level] -> boolean) that determines if logging should occur. Called at compile time.
Default implementation allows all logging.
Override this to implement custom filtering logic: (alter-var-root #'shimmer.core/log-filter-fn (constantly my-filter-fn))
Function (fn [namespace level] -> boolean) that determines
if logging should occur. Called at compile time.
Default implementation allows all logging.
Override this to implement custom filtering logic:
(alter-var-root #'shimmer.core/*log-filter-fn*
(constantly my-filter-fn))Function that performs actual logging.
Signature: (fn [name format kv-map] -> nil)
Where:
Override this to implement custom logging backends: (alter-var-root #'shimmer.core/log-fn (constantly my-custom-logger))
Function that performs actual logging.
Signature: (fn [name format kv-map] -> nil)
Where:
- name: formatted namespace string with CSS prefix (e.g. '%c[my.namespace]')
- format: CSS color string for the log level
- kv-map: map containing :msg, :line, and all user-provided key-values
Override this to implement custom logging backends:
(alter-var-root #'shimmer.core/*log-fn*
(constantly my-custom-logger))(compare-levels level1 level2)Compare two log levels. Returns:
Valid levels: :off, :error, :warn, :info, :debug, :all
This is a standard comparator function compatible with sort and other Clojure functions expecting comparators.
Examples: (compare-levels :debug :info) ; => 1 (debug > info) (compare-levels :error :warn) ; => -1 (error < warn) (compare-levels :info :info) ; => 0 (equal)
Compare two log levels. Returns: - Positive integer if level1 > level2 (more verbose) - Zero if level1 = level2 - Negative integer if level1 < level2 (less verbose) Valid levels: :off, :error, :warn, :info, :debug, :all This is a standard comparator function compatible with sort and other Clojure functions expecting comparators. Examples: (compare-levels :debug :info) ; => 1 (debug > info) (compare-levels :error :warn) ; => -1 (error < warn) (compare-levels :info :info) ; => 0 (equal)
(level-enabled? level threshold)Returns true if level should be logged given threshold.
This is the primary function for level comparison in config resolvers. A level is enabled if it is less than or equal to the threshold in verbosity.
Valid levels: :off, :error, :warn, :info, :debug, :all
Examples: (level-enabled? :info :debug) ; => true (info <= debug, so it's logged) (level-enabled? :debug :info) ; => false (debug > info, so it's filtered) (level-enabled? :warn :warn) ; => true (equal levels are enabled)
Typical usage in config resolver: (defn my-resolver [namespace level] (cond (= namespace "my-app.debug") (level-enabled? level :debug) (= namespace "my-app.core") (level-enabled? level :info) :else false))
Returns true if level should be logged given threshold.
This is the primary function for level comparison in config resolvers.
A level is enabled if it is less than or equal to the threshold in verbosity.
Valid levels: :off, :error, :warn, :info, :debug, :all
Examples:
(level-enabled? :info :debug) ; => true (info <= debug, so it's logged)
(level-enabled? :debug :info) ; => false (debug > info, so it's filtered)
(level-enabled? :warn :warn) ; => true (equal levels are enabled)
Typical usage in config resolver:
(defn my-resolver [namespace level]
(cond
(= namespace "my-app.debug") (level-enabled? level :debug)
(= namespace "my-app.core") (level-enabled? level :info)
:else false))(log level message & keyvals)Log a message at the specified level with optional keyvals key-value pairs.
The log macro performs TWO levels of filtering for zero-overhead logging:
Compile-time filtering: log-filter-fn is called during macro expansion. If it returns false, NO CODE is generated at all (zero overhead).
Runtime dead code elimination: The macro wraps log calls with guards:
When both are false in production builds, the Closure Compiler eliminates the entire log call, resulting in zero runtime artifacts.
To force logging in production (e.g., error-only), set the FORCE-LOGGING define in your build config: :closure-defines {shimmer.core/FORCE-LOGGING true}
Example: (log :info "User login" :user-id 123 :ip "192.168.1.1") (log :debug "Processing item" :item-id item :count (count items)) (log :error "Connection failed" :host host :error error)
Log a `message` at the specified `level` with optional `keyvals` key-value pairs.
- level: :trace, :debug, :info, :warn, :error, :off, :all
- lessage: string describing the log event
- leyvals: optional key-value pairs for context
The log macro performs TWO levels of filtering for zero-overhead logging:
1. Compile-time filtering: *log-filter-fn* is called during macro expansion.
If it returns false, NO CODE is generated at all (zero overhead).
2. Runtime dead code elimination: The macro wraps log calls with guards:
- js/goog.DEBUG (true in dev, false in production with :advanced optimization)
- shimmer.core/FORCE-LOGGING (Closure Define, default false)
When both are false in production builds, the Closure Compiler eliminates
the entire log call, resulting in zero runtime artifacts.
To force logging in production (e.g., error-only), set the FORCE-LOGGING
define in your build config:
:closure-defines {shimmer.core/FORCE-LOGGING true}
Example:
(log :info "User login" :user-id 123 :ip "192.168.1.1")
(log :debug "Processing item" :item-id item :count (count items))
(log :error "Connection failed" :host host :error error)cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |