Skip to content

Commit

Permalink
Use Timbre's default logging behavior in Babashka pod (#709)
Browse files Browse the repository at this point in the history
* test dthk stderr logging in run-native-image-tests

* disable :println appender explicitly

* only configure stderr logging outside Babashka

---------

Co-authored-by: Coby Tamayo <[email protected]>
  • Loading branch information
acobster and Coby Tamayo authored Sep 27, 2024
1 parent 6ba8f59 commit c88c3af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
15 changes: 14 additions & 1 deletion bb/resources/native-image-tests/run-native-image-tests
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]"
Expand Down
5 changes: 5 additions & 0 deletions bb/resources/native-image-tests/testconfig.attr-refs.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:store {:backend :file
:path "/tmp/dh-test-store" }
:keep-history? true
:attribute-refs? true
:schema-flexibility :write}
14 changes: 8 additions & 6 deletions src/datahike/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c88c3af

Please sign in to comment.