Skip to content

Commit

Permalink
initial draft
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughnd committed Sep 14, 2012
0 parents commit 804fa94
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
/target
/lib
/classes
/checkouts
pom.xml
*.jar
*.class
.lein-deps-sum
.lein-failures
.lein-plugins
15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
# clojure-example-logback-integration

Example of how to integrate logback into clojure.tools.logging. Also uses a log ns to delegate calls via macros so you can switch in timbre, etc.

Important parts are in project.clj, src/logback.xml, and log.clj.

## Usage

Test with 'lein run'

## License

Copyright © 2012 Vaughn Dickson

Distributed under the Eclipse Public License, the same as Clojure.
9 changes: 9 additions & 0 deletions project.clj
@@ -0,0 +1,9 @@
(defproject clojure-example-logback-integration "0.1.0-SNAPSHOT"
:description "Simple integration of logback into clojure.tools.logging with macro-ed logs to swap in other logging libs"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/tools.logging "0.2.4"]
[ch.qos.logback/logback-classic "1.0.7"]]
:main clojure-example-logback-integration.core)
12 changes: 12 additions & 0 deletions src/clojure_example_logback_integration/core.clj
@@ -0,0 +1,12 @@
(ns clojure-example-logback-integration.core
(:require [clojure-example-logback-integration.log :as log])
)

(defn -main
[& args]
(log/debug "Test debug log")
(log/info "Test info log")
(log/error "Test error log")
(try (throw (Exception. "Error, error"))
(catch Exception e (log/error e "Test exception logging")))
(println "Check your logs!"))
21 changes: 21 additions & 0 deletions src/clojure_example_logback_integration/log.clj
@@ -0,0 +1,21 @@
(ns clojure-example-logback-integration.log
(:require [clojure.tools.logging :as log]))

(defmacro debug [& args]
`(log/debug (str ~@args)))

(defmacro info [& args]
`(log/info (str ~@args)))

(defmacro warn [e & args]
`(log/warn (str ~@args) ~e))

(defmacro warn [& args]
`(log/warn (str ~@args)))

(defmacro error [& args]
`(log/error (str ~@args)))

(defmacro error [e & args]
`(log/error ~e (str ~@args)))

13 changes: 13 additions & 0 deletions src/logback.xml
@@ -0,0 +1,13 @@
<configuration debug="false">
<appender name="MAIN" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-10contextName %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<logger name="clojure-example-logback-integration" level="DEBUG"/>

<root level="INFO">
<appender-ref ref="MAIN"/>
</root>
</configuration>

0 comments on commit 804fa94

Please sign in to comment.