Liking cljdoc? Tell your friends :D

twig

Build Status Dependencies Status Clojars Project Tag Clojure version

A little logging helper for Clojure/ClojureScript projects

Table of Contents

Introduction

This is just a tiny bit of code, but it was starting to get duplicated around a bunch of projects, so now there's twig.

Screenshots

Clojure

Usage in a Clojure REPL:

Clojure screenshot

Clojurescript

Output in a Node.js app written in Clojurescript:

Clojurescript screenshot

Usage

Add to your project.clj:

[clojusc/twig "0.3.1"]

Then in a namespace of your choice:

(ns ...
  (:require [clojusc.twig :as logger])
  ...)

This will allow you to not only see nicely formatted log output (as configured in the included resources/logback.xml file), but also do things like setting the log level on a per-namespace basis:

(logger/set-level! '[com.datastax.driver
                     co.paralleluniverse]
                   :info)
(logger/set-level! 'my.project :debug)

Note that the level can be any of the levels supported by ch.qos.logback.classic Level (see the source code. As of now, those correspond to the following: :off, :error, :warn, :info, :debug, :trace, and :all. You may pass these as keywords, symbols, or strings.

:fatal is also supported; in Clojure this is aliased to :error, but in Clojurescipt it is its own level.

There are, of course, other things you can do besides setting the level. In Clojure (not Clojurescript), you can do the following:

(require [clojure.tools.logging :as log])

(log/debug "Logging agent:" log/*logging-agent*)
(log/debug "Logging factory:" (logger/get-factory))
(log/debug "Logging factory name:" (logger/get-factory-name))
(log/debug "Logger:" (logger/get-logger *ns*))
(log/debug "Logger name:" (logger/get-logger-name *ns*))
(log/debug "Logger level:" (logger/get-logger-level *ns*))
(log/debug "Logger context:" (logger/get-logger-context *ns*))
(log/debug "Logger configurator:" (logger/get-config *ns*))

License

Copyright © 2016-2018, Clojure-Aided Enrichment Center

Copyright © 2016, Element 84, Inc.

Copyright © 2015, Duncan McGreggor

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close