I tried both the solutions, neither worked.

Solution #1 - Use only clojure.tools.logging

My Dependencies
[[org.clojure/clojure "1.7.0"]
 [org.clojure/tools.logging "0.3.1"]]

Repl Output
> (require '[clojure.tools.logging :as ctl])
nil
> (ctl/error "hi")
nil
> (ctl/info "hi")
nil

Console Output
$ lein repl :headless :port 4005
nREPL server started on port 4005 on host 127.0.0.1 - nrepl://127.0.0.1:4005
Dec 17, 2015 12:07:16 PM clojure.tools.logging$eval406$fn__410 invoke
SEVERE: hi
Dec 17, 2015 12:07:22 PM clojure.tools.logging$eval406$fn__410 invoke
INFO: hi


Solution #2 - Add suggested dependencies

My Dependencies
[[org.clojure/clojure "1.7.0"]
 [org.clojure/tools.logging "0.3.1"]
 [org.slf4j/slf4j-log4j12 "1.7.13"]
 [org.slf4j/slf4j-api "1.7.13"]
 [log4j/log4j "1.2.17"]]

Repl Output
> (require '[clojure.tools.logging :as ctl])
nil
> (ctl/error "hi")
nil

Console Output
$ lein repl :headless :port 4005
nREPL server started on port 4005 on host 127.0.0.1 - nrepl://127.0.0.1:4005
2015-12-17 12:11:50 ERROR user:288 - hi

Am I missing something?

Other infomation:
$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

$ lein -v
Leiningen 2.5.3 on Java 1.8.0_45 Java HotSpot(TM) 64-Bit Server VM

Emacs 24.5
OS: Mac OS 10.10.5 


On Thursday, December 17, 2015 at 7:58:37 AM UTC+5:30, Shantanu Kumar wrote:
>
> Below is the order in which c.t.l picks up loggers:
> 1. SLF4j (which also includes Logback, since it natively implements the 
> SLF4j API)
> 2. Apache Commons-logging
> 3. Log4j
> 4. java.util.logging
>
> Reference: 
> https://github.com/clojure/tools.logging/blob/master/src/main/clojure/clojure/tools/logging/impl.clj#L214
>
> Both #1 and #2 are merely logger facade, incapable of logging anywhere 
> except to the console by themselves. They need an underlying logger for 
> real-world logging.
>
> Your dependencies only include the SLF4j-log4j bridge (without the log4j 
> dependency), which I am not sure is supposed to be picked up by c.t.l. I 
> would suggest either remove slf4j-log4j dependency altogether (allowing 
> j.u.l to be chosen) or add the slf4j [org.slf4j/slf4j-api "1.7.13"]
>  and log4j [log4j/log4j "1.2.17"] dependencies to your current config.
>
> Hope this helps.
>
> Shantanu
>
> On Wednesday, 16 December 2015 23:47:39 UTC+5:30, Mayank Jain wrote:
>>
>> Thanks Shantanu for your reply,
>>
>> It still didn't work.
>>
>> Here's my project.clj
>> (defproject log "0.1.0-SNAPSHOT"
>>   :description "FIXME: write description"
>>   :url "http://example.com/FIXME";
>>   :license {:name "Eclipse Public License"
>>             :url "http://www.eclipse.org/legal/epl-v10.html"}
>>   :dependencies [[org.clojure/clojure "1.7.0"]
>>                  [org.clojure/tools.logging "0.3.1"]
>>                  [org.slf4j/slf4j-log4j12 "1.7.13"]])
>>
>>
>> And here's my resources/log4j.properties file
>> # Root logger option
>> log4j.rootLogger=INFO, stdout
>>
>> # Direct log messages to stdout
>> log4j.appender.stdout=org.apache.log4j.ConsoleAppender
>> log4j.appender.stdout.Target=System.out
>> log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
>> log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} 
>> %-5p %c{1}:%L - %m%n
>>
>> And here's my the output from my Clojure repl in Emacs:
>> user> (require '[clojure.tools.logging :as ctl])
>> nil
>> user> (ctl/error "Fail!")
>> nil
>>
>> And here's what I get on my console
>> $ lein repl :headless :port 4005
>> nREPL server started on port 4005 on host 127.0.0.1 - nrepl://
>> 127.0.0.1:4005
>> 2015-12-16 23:44:50 ERROR user:288 - Fail!
>>
>> I would like it to print the same on both Emacs repl and on console (and 
>> add to a file).
>>
>> I can get it to write on console and file but not on repl.
>>
>> On Wednesday, December 16, 2015 at 10:13:12 PM UTC+5:30, Shantanu Kumar 
>> wrote:
>>>
>>> If you enabled Log4j console logger, the logs should appear in the REPL 
>>> too.
>>>
>>> See example at 
>>> http://www.mkyong.com/logging/log4j-log4j-properties-examples/
>>>
>>> You do not necessarily need log4j to log to the REPL via 
>>> clojure.tools.logging - you can just use c.t.l. without any logging library 
>>> and it will fall back to java.util.logging using STDOUT.
>>>
>>> Shantanu
>>>
>>> On Wednesday, 16 December 2015 21:58:40 UTC+5:30, Mayank Jain wrote:
>>>>
>>>> Hi,
>>>>
>>>> I would like to be able to print log statements 
>>>> via clojure.tools.logging to print on clojure repl as well.
>>>> I am using log4j logging framework for configurations.
>>>> Is this possible? I am unable to figure it out. 
>>>> I am open to any other logging framework if that solves this.
>>>>
>>>> Thanks.
>>>>
>>>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to