Skip to content

How to use logging

macourtney edited this page Sep 13, 2010 · 3 revisions
Clone this wiki locally

Added for version: 0.4
Updated for version: 0.7

Conjure comes will clojure.contrib.logging already set up for you using the java built in logging framework. To use it, simply require clojure.contrib.logging and call the functions in it.

Requiring Logging.

For example, to log “Kilroy was here.” as debug, first require clojure.contrib.logging:

(:require [clojure.contrib.logging :as logging])

Then call the debug function in logging:

(logging/debug "Kilroy was here")

Log Files and the Console

By default, when you’re in development mode, all log levels are printed to the console and the development.log file under the log directory. In production mode Everything is logged to the production.log file under the log directory, but only INFO and higher levels are logged to the console.

If you want to change the default log levels or otherwise change the logging configuration, you must do it in the environment config files.

The Environment Config Files

If you’ve used Conjure for a little while, you’ve probably run across the environment.clj file in the config directory. Many of the base configuration properties can be set in that file. Unfortunately, logging isn’t one of them since each mode, development, production, and test, logs differently. Therefore environment.clj calls the appropriate environment config file under the config/environments directory.

To update the log level of development, change the file config/environments/development.clj. Currently, the console logging level is set to ALL in the lines:

(.addFilter console-appender 
  (doto (new LevelRangeFilter)
    (.setLevelMin (. Level ALL))))

ALL is the log level for debug in log4j. To change the level to “INFO” change the line to:

(.addFilter console-appender 
  (doto (new LevelRangeFilter)
    (.setLevelMin (. Level INFO))))

Now only info level and higher logging statements will be printed to the console.

Something went wrong with that request. Please try again.