From c88c3af8a85dfb8b0f38f63ea1c3567cee7a7c34 Mon Sep 17 00:00:00 2001 From: Coby Tamayo Date: Fri, 27 Sep 2024 10:35:30 -0700 Subject: [PATCH] Use Timbre's default logging behavior in Babashka pod (#709) * test dthk stderr logging in run-native-image-tests * disable :println appender explicitly * only configure stderr logging outside Babashka --------- Co-authored-by: Coby Tamayo --- .../native-image-tests/run-native-image-tests | 15 ++++++++++++++- .../native-image-tests/testconfig.attr-refs.edn | 5 +++++ src/datahike/cli.clj | 14 ++++++++------ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 bb/resources/native-image-tests/testconfig.attr-refs.edn diff --git a/bb/resources/native-image-tests/run-native-image-tests b/bb/resources/native-image-tests/run-native-image-tests index fd5bbc271..14f67a545 100755 --- a/bb/resources/native-image-tests/run-native-image-tests +++ b/bb/resources/native-image-tests/run-native-image-tests @@ -5,9 +5,23 @@ set -o pipefail TMPSTORE=/tmp/dh-test-store CONFIG=bb/resources/native-image-tests/testconfig.edn +ATTR_REF_CONFIG=bb/resources/native-image-tests/testconfig.attr-refs.edn trap "rm -rf $TMPSTORE" EXIT +./dthk delete-database $ATTR_REF_CONFIG +./dthk create-database $ATTR_REF_CONFIG + +./dthk database-exists $ATTR_REF_CONFIG + +# test that warnings etc. get logged to stderr +LOG_OUTPUT="$(./dthk query '[:find ?e . :where [?e :nonexistent _]]' db:$ATTR_REF_CONFIG 2>&1 >/dev/null | grep ':nonexistent has not been found')" +if [ -z "$LOG_OUTPUT" ] +then + echo "Exception: binary did not log to stderr" + exit 1 +fi + ./dthk delete-database $CONFIG ./dthk create-database $CONFIG @@ -30,7 +44,6 @@ fi ./dthk query '[:find (count ?e) . :where [?e :name _]]' since:0:$CONFIG ./dthk query '[:find (count ?e) . :where [?e :name _]]' asof:0:$CONFIG - # other calls ./dthk pull db:$CONFIG "[:db/id, :name]" "1" ./dthk pull-many db:$CONFIG "[:db/id, :name]" "[1]" diff --git a/bb/resources/native-image-tests/testconfig.attr-refs.edn b/bb/resources/native-image-tests/testconfig.attr-refs.edn new file mode 100644 index 000000000..58de3e85c --- /dev/null +++ b/bb/resources/native-image-tests/testconfig.attr-refs.edn @@ -0,0 +1,5 @@ +{:store {:backend :file + :path "/tmp/dh-test-store" } + :keep-history? true + :attribute-refs? true + :schema-flexibility :write} diff --git a/src/datahike/cli.clj b/src/datahike/cli.clj index 134b7199f..3958a9ec9 100644 --- a/src/datahike/cli.clj +++ b/src/datahike/cli.clj @@ -16,12 +16,14 @@ ;; This file is following https://github.com/clojure/tools.cli -(log/merge-config! - {:appenders {:println {:doc "Always prints to *err*" - :enabled? true - :fn (fn log-to-stderr [{:keys [output_]}] - (binding [*out* *err*] - (println (force output_))))}}}) +(when-not (= "true" (System/getenv "BABASHKA_POD")) + (log/merge-config! + {:appenders {:println {:enabled? false} ;; leave a "paper trail" + :stderr {:doc "Always prints to *err*" + :enabled? true + :fn (fn log-to-stderr [{:keys [output_]}] + (binding [*out* *err*] + (println (force output_))))}}})) (defn usage [options-summary] (->> [datahike-logo