-
Notifications
You must be signed in to change notification settings - Fork 29
Dev: 2. Logging
Asami currently has limited logging. Feel free to contribute more!
Asami logging is done via the logging module in Zuko. By default, logging is disabled in Asami in order to avoid any overhead during normal runtime.
To enable logging, either set the logging.enabled
property for the Java runtime before startup, or ensure that it is set before loading the logging namespace. Assuming that Zuko and Asami are included in deps.edn
then logging can be enabled for a Clojure REPL with:
$ clj -J-Dlogging.enabled=true
Alternatively, in Java call (System/setProperty "logging.enabled" "true")
before loading the logging namespace.
Once logging has been enabled, the level will need to be set. The higher the log level, the more messages will be received. By default, the level is set to 0, meaning that nothing will be logged.
For instance, to set the log level for INFO
level messages and above (WARN
, ERROR
, and FATAL
), then use:
(require '[zuko.logging :as log])
(log/set-logging-level! :info)
Here is an example of setting up logging in a REPL:
$ clj -J-Dlogging.enabled=true
Clojure 1.10.2
user=> (require '[asami.core :as d])
nil
user=> (require '[zuko.logging :as log])
nil
user=> (log/set-logging-level! :trace)
6
user=> (def db-uri "asami:mem://dbname")
#'user/db-uri
user=> (d/create-database db-uri)
true
user=> (def conn (d/connect db-uri))
#'user/conn
user=> (d/transact conn
[{:person/name "Betty"
:person/address "53 Cobblestone Rd"}])
asami.index TRACE: insert [:tg/node-13432 :person/name "Betty" 1]
asami.index TRACE: insert [:tg/node-13432 :person/address "53 Cobblestone Rd" 1]
asami.index TRACE: insert [:tg/node-13432 :db/ident :tg/node-13432 1]
asami.index TRACE: insert [:tg/node-13432 :tg/entity true 1]
#object[java.util.concurrent.CompletableFuture 0x3d45ea17 "java.util.concurrent.CompletableFuture@3d45ea17[Not completed]"]
ClojureScript logging is slightly different due to the way macros are evaluated. You will need to ensure that logging is configured prior to logged namespaces being loaded. In Clojure, this can be changed at runtime. Otherwise, it is almost the same.
cljs -J-Dlogging.enabled=true
-R is deprecated, use -A with repl, -M for main, or -X for exec
WARNING: When invoking clojure.main, use -M
ClojureScript 1.10.773
cljs.user=> (require '[zuko.logging :as log])
nil
cljs.user=> (log/set-logging-level! :trace)
6
cljs.user=> (require '[asami.core :as d])
nil
cljs.user=> (def db-uri "asami:mem://dbname")
#'cljs.user/db-uri
cljs.user=> (def conn (d/connect db-uri))
#'cljs.user/conn
cljs.user=> (d/transact conn
[{:person/name "Betty"
:person/address "53 Cobblestone Rd"}])
asami.index TRACE: insert [:tg/node-1 :person/name "Betty" 1]
asami.index TRACE: insert [:tg/node-1 :person/address "53 Cobblestone Rd" 1]
asami.index TRACE: insert [:tg/node-1 :db/ident :tg/node-1 1]
asami.index TRACE: insert [:tg/node-1 :tg/entity true 1]
#object[cljs.core.Delay {:status :ready, :val {...}}]
The above ClojureScript was run using the following deps.edn
:
{:deps {org.clojure/clojurescript {:mvn/version "1.10.773"}
org.clojars.quoll/asami {:mvn/version "2.0.0-alpha3"}
org.clojars.quoll/zuko {:mvn/version "0.4.4"}
tailrecursion/cljs-priority-map {:mvn/version "1.2.1"}}}