Clojure.contrib.logging doesn’t have any way to set the log level. This is obviously a problem if you want to make use of various log levels (debug, warn, etc.) to separate different logging depths. Here’s a function to set the logging level on my default clojure.contrib.logging setup:

;;; This version works when (impl-get-log "") returns an org.apache.commons.logging.impl.Jdk14Logger
(use 'clojure.contrib.logging)
(defn set-log-level! [level]
  "Sets the root logger's level, and the level of all of its Handlers, to level.
   Level should be one of the constants defined in java.util.logging.Level."
  (let [logger (.getLogger (impl-get-log ""))]
    (.setLevel logger level)
    (doseq [handler (.getHandlers logger)]
      (. handler setLevel level))))
;;; This version works when (impl-get-log "") returns a java.util.logging.LogManager$RootLogger
(use 'clojure.contrib.logging)
(defn set-log-level! [level]
  "Sets the root logger's level, and the level of all of its Handlers, to level.
   Level should be one of the constants defined in java.util.logging.Level."
  (let [logger (impl-get-log "")]
    (.setLevel logger level)
    (doseq [handler (.getHandlers logger)]
      (. handler setLevel level))))

This log level setting function works with a standard out-of-the-box clojure.contrib.logger on my system — depending on what logging libraries it finds on your classpath, as per the docs, it may not work for you. In particular, you need to be using clojure.contrib.logger to wrap an Apache Commons Logging instance, which in turn wraps a java.util.logging instance. This is the way my system works without any configuration; YMMV. Hopefully, something like this will be assimilated into a universal wrapper in the next clojure.contrib.logging.

For the gory details of how this was constructed… Continue Reading »

Popularity: 45% [?]

Libcurl’s Java bindings now compile on Macintosh, with a few minor modifications to the Makefile. Get the code from my Github account.

Update: More recent Java bindings, which do not seem to be linked anywhere on the libcurl site, are available at http://www.gknw.net/viewvc/trunk/?root=curl-java. Still no multi support, though.

Popularity: 5% [?]

A Clojure version of my Yahoo Finance Ruby gem seemed like an interesting challenge and a good way to learn Clojure better. This version uses Apache HttpClient, which is significantly slower than libcurl. A libcurl version is on the way. Continue Reading »

Popularity: 45% [?]

Debuggers like JSwat and Eclipse can be remotely attached to live Clojure processes via TCP, but you have to tell the JVM to enable remote debugging when you start it. Leiningen does not presently have an (obvious) way to set java command line flags in project.clj, but it does pass the JAVA_OPTS environment variable to the JVM, so you can do:

JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n" lein swank
# or "lein repl", etc.

to enable remote debugging. Watch the output for the port it allocates, and put that into JSwat/Eclipse/etc. Continue Reading »

Popularity: 12% [?]

Rincanter allows one to access the R statistical programming language from Clojure. Rincanter also integrates R with Incanter for charting and more stats. Rincanter is based on rJava‘s JRI R-from-Java bridge. Getting this working required making a JNI library available to Clojure via an as-yet-undocumented Leiningen setting, :native-path. Continue Reading »

Popularity: 17% [?]

Memoize in Clojure is cool. Memoize is even built in to the core Clojure API. Resetting the built-in version is impossible since the atom used as a cache is hidden in a closure, but it’s easy to write a custom resettable version. Here are two versions that we came up with on IRC today. Continue Reading »

Popularity: 40% [?]

Yahoo! Finance allows clients to download free historic stock data. Transparentech’s YahooFinance Ruby gem works well, but getting historic data for a large number of symbols is painfully slow. YahooFinance (the gem)’s download of the end-of-day historic quotes for about 10,000 symbols was taking 2 hours or more. With Typhoeus and its parallel connections, I can run the same download in under 7 minutes.

Paul Dix’s Typhoeus appeared while Googling today. Not only is it an awesomely fast wrapper for libcurl, it allows you to queue requests and then execute them concurrently.

Update: I’ve just released a Ruby gem based on this code. It’s on Gemcutter, and the source is on GitHub. You can install it by just doing a “sudo gem install yahoofinance-typhoeus“.
Continue Reading »

Popularity: 48% [?]

jQuery’s Tablesorter is easily customizable to sort by absolute value or anything else you’d like. In my case, I have a column of “standard deviations above or below the mean” that I want to display sorted by absolute value. This was pretty easy with a little Javascript code. Continue Reading »

Popularity: 38% [?]