            (net.logstash.log4j JSONEventLayoutV1 JSONEventLayout)
            (org.apache.log4j.spi RootLogger))
   (:import (org.apache.log4j.rolling TimeBasedRollingPolicy
+                                     SizeBasedTriggeringPolicy
+                                     FixedWindowRollingPolicy
                                      RollingFileAppender))
   (:import org.apache.commons.logging.LogFactory)
   (:require wall.hack))

      (.addAppender logger (ConsoleAppender. (get-layout console-layout))))

    (when file
      (let [rolling-policy (doto (TimeBasedRollingPolicy.)
                             (.setActiveFileName file)
                             (.setFileNamePattern
                              (str file ".%d{yyyy-MM-dd}.gz"))
                             (.activateOptions))
            log-appender (doto (RollingFileAppender.)
                           (.setRollingPolicy rolling-policy)
                           (.setLayout (get-layout :riemann))
                           (.activateOptions))]
        (.addAppender logger log-appender)))

    (when files
      (doseq [{:keys [path layout]} files
              :let [layout (get-layout layout)]]
        (let [rolling-policy (doto (TimeBasedRollingPolicy.)
                             (.setActiveFileName path)
                             (.setFileNamePattern
                              (str path ".%d{yyyy-MM-dd}.gz"))
                             (.activateOptions))
            log-appender (doto (RollingFileAppender.)
                           (.setRollingPolicy rolling-policy)
                           (.setLayout layout)
                           (.activateOptions))]
        (.addAppender logger log-appender))))

    ;; Set levels.
    (.setLevel logger Level/INFO)

    (set-level "riemann.client" Level/DEBUG)
    (set-level "riemann.server" Level/DEBUG)

  :files           A list of files to log to. If provided, a seq is expected
                   containing maps with a :path and an optional :layout key
                   which can be any of: :riemann, :json-event :json-eventv1
  :logsize-rotate  If size(bytes) is specified rotate based on that size
                   otherwise use default time based.
  Example:

  (init {:console false :file \"/var/log/riemann.log\"})
    or
  (init {:console false :file \"/var/log/riemann.log\" :logsize-rotate 1000000000})"
  [& opts]
  ;; Reset loggers
  (let [{:keys [file
                files
                console-layout
                logsize-rotate]
         :as opts} (if (and (= 1 (count opts))
                            (map? (first opts)))
                     (first opts)
