Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 78 lines (50 sloc) 3.29 kB
4ee2065 @abedra Initial conversion
abedra authored
1 # Logging
2
ec33ac5 Put slf4j ahead of commons-logging.
Alexander Taggart authored
3 Logging macros which delegate to a specific logging implementation. At runtime a specific implementation is selected from, in order, slf4j, Apache commons-logging, log4j, and finally java.util.logging.
727bf48 Formatting and correcting errors in README
Alexander Taggart authored
4
5 Logging levels are specified by clojure keywords corresponding to the values used in log4j and commons-logging:
4ee2065 @abedra Initial conversion
abedra authored
6
7 :trace, :debug, :info, :warn, :error, :fatal
8
e7a8aa8 @ataggart Tweaked README.
ataggart authored
9 Logging occurs with the `log` macro, or the level-specific convenience macros, which write either directly or via an agent. The log macros will not evaluate their message arguments unless the specific logging level is in effect. Alternately, you can use the `spy` macro when you have code that needs to be evaluated, and also want to output the code and its result to the log.
727bf48 Formatting and correcting errors in README
Alexander Taggart authored
10
e7a8aa8 @ataggart Tweaked README.
ataggart authored
11 Unless otherwise specified, the current namespace (as identified by `*ns*`) will be used as the log-ns (similar to how the java class name is usually used). Note: your logging configuration should display the name that was passed to the logging implementation, and not perform stack-inspection, otherwise you'll see some ugly and unhelpful text in your logs.
727bf48 Formatting and correcting errors in README
Alexander Taggart authored
12
25b7ec9 @ataggart Tweak the readme.
ataggart authored
13 Use the `enabled?` macro to write conditional code against the logging level (beyond simply whether or not to call log, which is handled automatically).
727bf48 Formatting and correcting errors in README
Alexander Taggart authored
14
25b7ec9 @ataggart Tweak the readme.
ataggart authored
15 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 (e.g., "com.example.captured") must be specified in order to namespace the output.
4ee2065 @abedra Initial conversion
abedra authored
16
17 ## Usage
18
f5b9255 @abedra Adding a small code example to demonstrate usage
abedra authored
19 The following short example should give you what you need to get started:
20
21 (ns example.core
22 (:use [clojure.tools.logging :only (info error)]))
23
e1dbfaf @ataggart Fix TLOG-5: improve example code
ataggart authored
24 (defn divide [x x]
f5b9255 @abedra Adding a small code example to demonstrate usage
abedra authored
25 (try
e1dbfaf @ataggart Fix TLOG-5: improve example code
ataggart authored
26 (info "dividing" x "by" y)
27 (/ one two)
286f891 @abedra Edited README.md via GitHub
abedra authored
28 (catch Exception ex
727bf48 Formatting and correcting errors in README
Alexander Taggart authored
29 (error ex "There was an error in calculation"))))
f5b9255 @abedra Adding a small code example to demonstrate usage
abedra authored
30
25b7ec9 @ataggart Tweak the readme.
ataggart authored
31 For those new to using a java logging library, the following is a very basic configuration for log4j. Place it in a file called `log4j.properties` and place that file (and the log4j JAR) on the classpath.
4ee2065 @abedra Initial conversion
abedra authored
32
33 log4j.rootLogger=WARN, A1
34 log4j.logger.user=DEBUG
35 log4j.appender.A1=org.apache.log4j.ConsoleAppender
36 log4j.appender.A1.layout=org.apache.log4j.PatternLayout
37 log4j.appender.A1.layout.ConversionPattern=%d %-5p %c: %m%n
38
25b7ec9 @ataggart Tweak the readme.
ataggart authored
39 The above will print messages to the console for `:debug` or higher if one is in the `user` namespace, and `:warn` or higher in all other namespaces.
4ee2065 @abedra Initial conversion
abedra authored
40
e7a8aa8 @ataggart Tweaked README.
ataggart authored
41 ### Installation
4ee2065 @abedra Initial conversion
abedra authored
42
43 Logging is available in Maven central. Add it to your Maven project's `pom.xml`:
44
45 <dependency>
46 <groupId>org.clojure</groupId>
47 <artifactId>tools.logging</artifactId>
a71650b @ataggart Updated README to reference latest version.
ataggart authored
48 <version>0.2.3</version>
4ee2065 @abedra Initial conversion
abedra authored
49 </dependency>
50
51 or your leiningen project.clj:
52
a71650b @ataggart Updated README to reference latest version.
ataggart authored
53 [org.clojure/tools.logging "0.2.3"]
4ee2065 @abedra Initial conversion
abedra authored
54
55 Please note the changelog below.
56
57 ### Building Logging
58
59 0. Clone the repo
60 1. Make sure you have maven installed
61 2. Run the maven build; run either:
88dcece @abedra Correcting some errors in the README
abedra authored
62 1. `mvn install`: This will produce a logging jar file in the `target`
4ee2065 @abedra Initial conversion
abedra authored
63 directory, and run all tests with the most recently-released build
e7a8aa8 @ataggart Tweaked README.
ataggart authored
64 of Clojure.
4ee2065 @abedra Initial conversion
abedra authored
65
66 ## Thanks
67
68 * Chris Dean
69 * Phil Hagelberg
70 * Richard Newman
71 * Timothy Pratley
72
73 ## License
74
75 Copyright © 2009 Alex Taggart
76
77 Licensed under the EPL. (See the file epl.html.)
Something went wrong with that request. Please try again.