Logging macros which delegate to a specific logging implementation, selected
at runtime when the clojure.tools.logging
namespace is first loaded.
Lastest stable release is 0.5.0
Leiningen:
[org.clojure/tools.logging "0.5.0"]
Maven:
<dependency>
<groupId>org.clojure</groupId>
<artifactId>tools.logging</artifactId>
<version>0.5.0</version>
</dependency>
Gradle:
compile "org.clojure:tools.logging:0.5.0"
Logging occurs with the log
macro, or the level-specific convenience macros
(e.g., debug
, debugf
). Only when the specified logging level is enabled will
the message arguments be evaluated and the underlying logging implementation be
invoked. By default that invocation will occur via an agent when inside a running
STM transaction.
Unless otherwise specified, the current namespace (as identified by *ns*
) will
be used as the log-ns. This value can be emitted in the log entry, and used by most
logging implementations when using namespace-specific logging levels.
Note: You should configure your logging implementation to display the name that was passed to it. If it instead performs stack-inspection you'll see some ugly and unhelpful text in your logs.
You can redirect all java writes of System.out
and System.err
to the log
system by calling log-capture!
. To bind *out*
and *err*
to the log system
invoke with-logs
. In both cases a log-ns value must be specified in order to
namespace the output.
NOTE: Logging configuration (e.g., setting of logging levels, formatting) is specific to the underlying logging implementation, and is out of scope for this library.
To control which logging implementation is used, set the clojure.tools.logging.factory
system property to the fully-qualified name of a no-arg function that returns an
instance of clojure.tools.logging.impl/LoggerFactory
. There are a number of
factory functions provided in the clojure.tools.logging.impl
namespace.
:jvm-opts ["-Dclojure.tools.logging.factory=clojure.tools.logging.impl/slf4j-factory"]
If the system property is unset, an implementation will be automatically chosen based on whichever of the following implementations is successfully loaded first:
The above approach is problematic given that applications often inadvertently pull in multiple logging implementations as transitive dependencies. As such, it is strongly advised that you set the system property.
Copyright © 2009 Alex Taggart
Licensed under the EPL. (See the file epl.html.)
Can you improve this documentation? These fine people already did:
Alexander Taggart, Aaron Bedra & laurentpetitEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close