public
Fork of mojombo/god
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/topfunky/god.git
add --no-syslog
mojombo (author)
Thu Jan 10 11:27:36 -0800 2008
commit  8b62e3329ebcb21268175abf081136b586970c44
tree    660e508a4387072a7c1e853cfa01ecb02edf988e
parent  220164aa09fbe0da9527c214d57836559b3bd602
...
1
2
3
 
...
1
2
3
4
0
@@ -1,3 +1,4 @@
0
 coverage
0
 pkg
0
 *.log
0
+logs
...
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
0
@@ -1,3 +1,7 @@
0
+== 0.6.7 /
0
+ * Minor Enhancements
0
+ * Add --no-syslog option to disable Syslog
0
+
0
 == 0.6.6 / 2008-01-07
0
   * Bug Fixes
0
     * Redo Timer mutexing to reduce synchronization needs
...
9
10
11
12
 
13
14
15
...
72
73
74
75
 
76
77
 
 
 
 
78
79
80
81
82
83
 
84
85
86
...
9
10
11
 
12
13
14
15
...
72
73
74
 
75
76
77
78
79
80
81
82
83
84
85
86
 
87
88
89
90
0
@@ -9,7 +9,7 @@ require 'optparse'
0
 require 'drb'
0
 
0
 begin
0
- options = {:daemonize => true, :port => 17165}
0
+ options = {:daemonize => true, :port => 17165, :syslog => true}
0
 
0
   opts = OptionParser.new do |opts|
0
     opts.banner = <<-EOF
0
@@ -72,15 +72,19 @@ begin
0
       options[:info] = true
0
     end
0
     
0
- opts.on("--log-level LEVEL", "Log level [debug|info|fatal]") do |x|
0
+ opts.on("--log-level LEVEL", "Log level [debug|info|warn|error|fatal]") do |x|
0
       options[:log_level] = x.to_sym
0
     end
0
+
0
+ opts.on("--no-syslog", "Disable output to syslog") do
0
+ options[:syslog] = false
0
+ end
0
   end
0
   
0
   opts.parse!
0
   
0
   # validate
0
- if options[:log_level] && ![:debug, :info, :fatal].include?(options[:log_level])
0
+ if options[:log_level] && ![:debug, :info, :warn, :error, :fatal].include?(options[:log_level])
0
     abort("Invalid log level '#{options[:log_level]}'")
0
   end
0
   
...
8
9
10
11
12
13
14
...
58
59
60
 
 
61
62
63
...
76
77
78
79
80
81
82
83
84
85
86
87
88
...
196
197
198
 
 
199
200
201
...
566
567
568
 
 
569
570
571
...
8
9
10
 
11
12
13
...
57
58
59
60
61
62
63
64
...
77
78
79
 
 
 
 
 
 
 
80
81
82
...
190
191
192
193
194
195
196
197
...
562
563
564
565
566
567
568
569
0
@@ -8,7 +8,6 @@ require 'stringio'
0
 require 'logger'
0
 
0
 # stdlib
0
-require 'syslog'
0
 
0
 # internal requires
0
 require 'god/errors'
0
@@ -58,6 +57,8 @@ require 'god/sugar'
0
 require 'god/cli/version'
0
 require 'god/cli/command'
0
 
0
+require 'god/diagnostics'
0
+
0
 $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext god])
0
 
0
 # App wide logging system
0
@@ -76,13 +77,6 @@ $run ||= nil
0
 
0
 GOD_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
0
 
0
-# Ensure that Syslog is open
0
-begin
0
- Syslog.open('god')
0
-rescue RuntimeError
0
- Syslog.reopen('god')
0
-end
0
-
0
 # Return the binding of god's root level
0
 def root_binding
0
   binding
0
@@ -196,6 +190,8 @@ module God
0
     # log level
0
     log_level_map = {:debug => Logger::DEBUG,
0
                      :info => Logger::INFO,
0
+ :warn => Logger::WARN,
0
+ :error => Logger::ERROR,
0
                      :fatal => Logger::FATAL}
0
     LOG.level = log_level_map[self.log_level]
0
     
0
@@ -566,6 +562,8 @@ module God
0
     # mark as running
0
     self.running = true
0
     
0
+ # start_dike
0
+
0
     # join the timer thread so we don't exit
0
     Timer.get.join
0
   end
...
50
51
52
53
54
55
 
 
56
57
58
59
 
 
 
 
 
 
 
60
61
62
...
50
51
52
 
 
 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
0
@@ -50,13 +50,19 @@ module God
0
               God.pid = @options[:pid]
0
             end
0
             
0
- # set log level if requested
0
- if @options[:log_level]
0
- God.log_level = @options[:log_level]
0
+ unless @options[:syslog]
0
+ Logger.syslog = false
0
             end
0
             
0
             # load config
0
             if @options[:config]
0
+ # set log level, defaults to WARN
0
+ if @options[:log_level]
0
+ God.log_level = @options[:log_level]
0
+ else
0
+ God.log_level = :warn
0
+ end
0
+
0
               unless File.exist?(@options[:config])
0
                 abort "File not found: #{@options[:config]}"
0
               end
...
9
10
11
 
 
 
 
 
 
 
12
13
14
15
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
 
 
 
 
 
 
33
34
35
...
49
50
51
52
 
53
54
 
 
 
 
 
55
56
57
...
65
66
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69
70
71
...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
 
 
 
 
 
 
 
 
 
 
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
70
71
72
 
73
74
75
76
77
78
79
80
81
82
83
...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
0
@@ -9,27 +9,48 @@ module God
0
     
0
     attr_accessor :logs
0
     
0
+ class << self
0
+ attr_accessor :syslog
0
+ end
0
+
0
+ self.syslog ||= true
0
+
0
+ # Instantiate a new Logger object
0
     def initialize
0
       super($stdout)
0
       self.logs = {}
0
       @mutex = Mutex.new
0
       @capture = nil
0
+ load_syslog
0
     end
0
     
0
- def start_capture
0
- @mutex.synchronize do
0
- @capture = StringIO.new
0
- end
0
- end
0
-
0
- def finish_capture
0
- @mutex.synchronize do
0
- cap = @capture.string
0
- @capture = nil
0
- cap
0
+ # If Logger.syslog is true then attempt to load the syslog bindings. If syslog
0
+ # cannot be loaded, then set Logger.syslog to false and continue.
0
+ #
0
+ # Returns nothing
0
+ def load_syslog
0
+ return unless Logger.syslog
0
+
0
+ begin
0
+ require 'syslog'
0
+
0
+ # Ensure that Syslog is open
0
+ begin
0
+ Syslog.open('god')
0
+ rescue RuntimeError
0
+ Syslog.reopen('god')
0
+ end
0
+ rescue Exception
0
+ Logger.syslog = false
0
       end
0
     end
0
     
0
+ # Log a message
0
+ # +watch+ is the String name of the Watch (may be nil if not Watch is applicable)
0
+ # +level+ is the log level [:debug|:info|:warn|:error|:fatal]
0
+ # +text+ is the String message
0
+ #
0
+ # Returns nothing
0
     def log(watch, level, text)
0
       # initialize watch log if necessary
0
       self.logs[watch.name] ||= Timeline.new(God::LOG_BUFFER_SIZE_DEFAULT) if watch
0
@@ -49,9 +70,14 @@ module God
0
       self.send(level, text % [])
0
       
0
       # send to syslog
0
- Syslog.send(SYSLOG_EQUIVALENTS[level], text)
0
+ Syslog.send(SYSLOG_EQUIVALENTS[level], text) if Logger.syslog
0
     end
0
     
0
+ # Get all log output for a given Watch since a certain Time.
0
+ # +watch_name+ is the String name of the Watch
0
+ # +since+ is the Time since which to fetch log lines
0
+ #
0
+ # Returns String
0
     def watch_log_since(watch_name, since)
0
       # initialize watch log if necessary
0
       self.logs[watch_name] ||= Timeline.new(God::LOG_BUFFER_SIZE_DEFAULT)
0
@@ -65,6 +91,29 @@ module God
0
         end.join
0
       end
0
     end
0
+
0
+ # private
0
+
0
+ # Enable capturing of log
0
+ #
0
+ # Returns nothing
0
+ def start_capture
0
+ @mutex.synchronize do
0
+ @capture = StringIO.new
0
+ end
0
+ end
0
+
0
+ # Disable capturing of log and return what was captured since
0
+ # capturing was enabled with Logger#start_capture
0
+ #
0
+ # Returns String
0
+ def finish_capture
0
+ @mutex.synchronize do
0
+ cap = @capture.string
0
+ @capture = nil
0
+ cap
0
+ end
0
+ end
0
   end
0
   
0
 end
0
\ No newline at end of file
...
89
90
91
 
92
93
94
...
89
90
91
92
93
94
95
0
@@ -89,6 +89,7 @@ module God
0
             applog(nil, :fatal, message)
0
           ensure
0
             # sleep until next check
0
+ GC.start
0
             sleep INTERVAL
0
           end
0
         end

Comments

    No one has commented yet.