Skip to content

Commit a6fcc6e

Browse files
author
Nathan Marz
committed
redirect all stdio to regular worker log file
1 parent 8833764 commit a6fcc6e

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/clj/backtype/storm/daemon/worker.clj

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
(defserverfn mk-worker [conf mq-context storm-id supervisor-id port worker-id]
7777
(log-message "Launching worker for " storm-id " on " supervisor-id ":" port " with id " worker-id
7878
" and conf " conf)
79+
(if-not (local-mode? conf)
80+
(redirect-stdio-to-log4j!))
7981
(let [active (atom true)
8082
storm-active-atom (atom false)
8183
cluster-state (cluster/mk-distributed-cluster-state conf)

src/clj/backtype/storm/log.clj

+6
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515

1616
(defmacro log-warn [& args]
1717
`(log/warn (str ~@args)))
18+
19+
(defn log-capture! [& args]
20+
(apply log/log-capture! args))
21+
22+
(defn log-stream [& args]
23+
(apply log/log-stream args))

src/clj/backtype/storm/util.clj

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(:import [org.apache.commons.io FileUtils])
1414
(:import [org.apache.commons.exec ExecuteException])
1515
(:import [org.json.simple JSONValue])
16-
(:import [java.util Timer])
16+
(:import [clojure.lang RT])
1717
(:require [clojure.contrib [str-utils2 :as str]])
1818
(:require [clojure [set :as set]])
1919
(:use [clojure walk])
@@ -568,3 +568,13 @@
568568
(cond ~@guards
569569
true (throw ~error-local)
570570
)))))
571+
572+
(defn redirect-stdio-to-log4j! []
573+
;; set-var-root doesn't work with *out* and *err*, so digging deeper here
574+
(.set RT/OUT (java.io.OutputStreamWriter.
575+
(log-stream :info "STDIO")))
576+
(.set RT/ERR (PrintWriter.
577+
(java.io.OutputStreamWriter.
578+
(log-stream :error "STDIO"))
579+
true))
580+
(log-capture! "STDIO"))

0 commit comments

Comments
 (0)