Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Logging

Alexander Yakushev edited this page Apr 6, 2015 · 4 revisions

Android has an embedded logging facility, in the form of android.util.Log class. If for whatever reason you don’t want to use the approaches listed below, calling Log’s methods via interop is also perfectly fine.

This namespace is a small wrapper around Log class. It contains five macros you can use:

  • d - debug
  • e - error
  • i - info
  • v - verbose
  • w - warning

Each logging macro takes variable number of arguments which it concatenates. You can also provide optional keyword arguments - :exception and :tag. The former, when followed by Exception object, will print its stacktrace. The latter allows you to set the custom tag for the log message (by default the current namespace is used as a tag). Examples:

(require '[neko.log :as log])

(log/d "Some log string" {:foo 1, :bar 2})
(log/i "Logging to custom tag" [1 2 3] :tag "custom")
(log/e "Something went wrong" [1 2 3] :exception ex)

You can also omit certain log types from being executed (for example, to drop all debug logs from your release build). In order to do so, you have to specify :ignore-log-priority option in your project.clj.

If you are developing a cross-platform application, you may want to use a unified logging solution that will work on both all platforms at once. clojure.tools.logging exists exactly for this purpose, it is a facade that delegates the actual logging to the implementation present on the classpath. Original tools.logging doesn’t work on Android out of the box, but our Clojars group contains a patched version (also supports Skummet):

http://clojars.org/org.clojure-android/tools.logging/latest-version.svg

This version is compatible with both Android and other platforms, so you can use this single dependency in all of your profiles. When built for Android tools.logging uses Log class to print out statements, so it is the same as calling neko.log or using interop — but now you can use the same logging tool across your whole multi-platform application. Learn how to use tools.logging by visiting its Github repository.