storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptgo...@apache.org
Subject [08/24] git commit: logviewer locates log directory via appender named in storm config
Date Tue, 19 Nov 2013 15:26:45 GMT
logviewer locates log directory via appender named in storm config

exits on startup if it can't find the appender


Project: http://git-wip-us.apache.org/repos/asf/incubator-storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-storm/commit/cbb13638
Tree: http://git-wip-us.apache.org/repos/asf/incubator-storm/tree/cbb13638
Diff: http://git-wip-us.apache.org/repos/asf/incubator-storm/diff/cbb13638

Branch: refs/heads/master
Commit: cbb13638165c36f0996eff2deda0bc03b7d48252
Parents: 242108d
Author: Homer Strong <homer.strong@gmail.com>
Authored: Wed Oct 16 14:07:09 2013 -0700
Committer: Homer Strong <homer.strong@gmail.com>
Committed: Wed Oct 16 14:07:09 2013 -0700

----------------------------------------------------------------------
 .../src/clj/backtype/storm/daemon/logviewer.clj | 38 +++++++++++++-------
 1 file changed, 25 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/cbb13638/storm-core/src/clj/backtype/storm/daemon/logviewer.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/backtype/storm/daemon/logviewer.clj b/storm-core/src/clj/backtype/storm/daemon/logviewer.clj
index 1be017d..92ef556 100644
--- a/storm-core/src/clj/backtype/storm/daemon/logviewer.clj
+++ b/storm-core/src/clj/backtype/storm/daemon/logviewer.clj
@@ -31,14 +31,20 @@
     ))
 
 (defn log-root-dir
-  []
-  (let [appender (first (iterator-seq (.iteratorForAppenders (LoggerFactory/getLogger Logger/ROOT_LOGGER_NAME))))]
-    (if (and appender (instance? FileAppender appender))
+  "Given an appender name, as configured, get the parent directory of the appender's log
file.
+
+Note that if anything goes wrong, this will throw an Error and exit."
+  [appender-name]
+  (let [appender (.getAppender (LoggerFactory/getLogger Logger/ROOT_LOGGER_NAME) appender-name)]
+    (if (and appender-name appender (instance? FileAppender appender))
       (.getParent (File. (.getFile appender)))
-      (.getCanonicalPath (File. (System/getProperty "storm.home") "logs")))))
+      (do
+        (throw
+         (Error. "Log viewer could not find configured appender, or the appender is not a
FileAppender. Please check that the appender name configured in storm.yaml and cluster.xml
agree."))
+        (System/exit 1)))))
 
-(defn log-page [file tail grep]
-  (let [path (.getCanonicalPath (File. (log-root-dir) file))
+(defn log-page [file tail grep root-dir]
+  (let [path (.getCanonicalPath (File. root-dir file))
         tail (if tail
                (min 10485760 (Integer/parseInt tail))
                10240)
@@ -71,8 +77,8 @@
     ]))
 
 (defroutes log-routes
-  (GET "/log" [:as {cookies :cookies} & m]
-       (log-template (log-page (:file m) (:tail m) (:grep m))))
+  (GET "/log" [:as req & m]
+       (log-template (log-page (:file m) (:tail m) (:grep m) (:log-root req))))
   (GET "/loglevel" [:as {cookies :cookies} & m]
        (log-template (log-level-page (:name m) (:level m))))
   (route/resources "/")
@@ -82,10 +88,16 @@
   (handler/site log-routes)
  )
 
-(defn start-logviewer [port]
-  (run-jetty logapp {:port port}))
+(defn conf-middleware
+  "For passing the storm configuration with each request."
+  [app log-root]
+  (fn [req]
+    (app (assoc req :log-root log-root))))
 
-(defn -main []
-  (let [conf (read-storm-config)]
-    (start-logviewer (int (conf LOGVIEWER-PORT)))))
+(defn start-logviewer [port conf]
+  (run-jetty (conf-middleware logapp conf) {:port port}))
 
+(defn -main []
+  (let [conf (read-storm-config)
+        log-root (log-root-dir (conf LOGVIEWER-APPENDER-NAME))]
+    (start-logviewer (int (conf LOGVIEWER-PORT)) log-root)))


Mime
View raw message