From 614460790a46a0360afb47fca6e2875deb90ea94 Mon Sep 17 00:00:00 2001 From: rossputin Date: Mon, 16 Feb 2015 16:26:20 +0000 Subject: [PATCH] [#93] Create spit appender path if it does not exist (@rossputin) --- src/taoensso/timbre.clj | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index 3b935b4..f1e24ae 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -3,7 +3,8 @@ (:require [clojure.string :as str] [io.aviso.exception :as aviso-ex] [taoensso.encore :as enc]) - (:import [java.util Date Locale] + (:import java.io.File + [java.util Date Locale] [java.text SimpleDateFormat])) ;;;; Encore version check @@ -269,11 +270,21 @@ "UnknownHost"))) (deref 5000 "UnknownHost"))))) +(defn- exists? + [path] + (when-not (str/blank? path) (.exists (File. ^String path)))) + +(defn- mkdirs "Creates all parent directories for the passed file." + [^File f] + (.mkdirs (.getParentFile (.getCanonicalFile f)))) + (defn- wrap-appender-juxt "Wraps compile-time appender juxt with additional runtime capabilities (incl. middleware) controlled by compile-time config. Like `wrap-appender-fn` but operates on the entire juxt at once." [config juxtfn] + (when-let [spit-file (get-in config [:shared-appender-config :spit-filename])] + (when-not (exists? spit-file) (mkdirs (File. spit-file)))) (->> ; Wrapping applies per juxt, bottom-to-top juxtfn