Permalink
Browse files

riemann.logging/init won't log to a file unless asked.

We also set up a default console logger on startup.
  • Loading branch information...
1 parent fa11480 commit 1c5e9daf8614112636967f74076a77f3c15e81e2 @aphyr aphyr committed Dec 6, 2012
Showing with 34 additions and 25 deletions.
  1. +1 −0 riemann.config
  2. +11 −8 src/riemann/bin.clj
  3. +22 −17 src/riemann/logging.clj
View
@@ -5,6 +5,7 @@
(tcp-server)
(udp-server)
(ws-server)
+(repl-server)
(periodically-expire 10)
View
@@ -1,6 +1,7 @@
(ns riemann.bin
"Main function."
(:require riemann.config
+ riemann.logging
riemann.time)
(:use clojure.tools.logging)
(:gen-class))
@@ -38,11 +39,13 @@
(defn -main
"Start Riemann. Loads a configuration file from the first of its args."
[& argv]
- (try
- (reset! config-file (or (first argv) "riemann.config"))
- (handle-signals)
- (riemann.time/start!)
- (reload)
- nil
- (catch Exception e
- (error "Couldn't start" e))))
+ (riemann.logging/init)
+ (try
+ (reset! config-file (or (first argv) "riemann.config"))
+ (handle-signals)
+ (riemann.time/start!)
+ (riemann.config/include @config-file)
+ (riemann.config/start)
+ nil
+ (catch Exception e
+ (error "Couldn't start" e))))
View
@@ -20,28 +20,33 @@
[logger level]
(. (Logger/getLogger logger) (setLevel level)))
-(def riemann-layout (EnhancedPatternLayout. "%p [%d] %t - %c - %m%n%throwable%n"))
+(def riemann-layout
+ "A nice format for log lines."
+ (EnhancedPatternLayout. "%p [%d] %t - %c - %m%n%throwable%n"))
(defn init
"Initialize log4j. You will probably call this from the config file. Options:
- :file The file to log to.
- Use \"/dev/null\" on *nix or \"NUL:\" on Windows to log to stdout only."
+ :file The file to log to. If omitted, logs to console only."
[& { :keys [file] }]
- (let [filename (or file "riemann.log")
- rolling-policy (doto (TimeBasedRollingPolicy.)
- (.setActiveFileName filename)
- (.setFileNamePattern
- (str filename ".%d{yyyy-MM-dd}.gz"))
- (.activateOptions))
- log-appender (doto (RollingFileAppender.)
- (.setRollingPolicy rolling-policy)
- (.setLayout riemann-layout)
- (.activateOptions))]
- (doto (Logger/getRootLogger)
- (.removeAllAppenders)
- (.addAppender log-appender)
- (.addAppender (ConsoleAppender. riemann-layout))))
+ ; Reset loggers
+ (doto (Logger/getRootLogger)
+ (.removeAllAppenders)
+ (.addAppender (ConsoleAppender. riemann-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 riemann-layout)
+ (.activateOptions))]
+ (.addAppender (Logger/getRootLogger) log-appender)))
+
+ ; Set levels.
(. (Logger/getRootLogger) (setLevel Level/INFO))
(set-level "riemann.client" Level/DEBUG)

0 comments on commit 1c5e9da

Please sign in to comment.