Module: Zeusd::DaemonTracker

Included in:
Daemon
Defined in:
lib/zeusd/daemon_tracker.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/zeusd/daemon_tracker.rb', line 22

def self.included(base)
  tracked_methods = [:start!, :stop!, :restart!, :start_child_process!]
  base.instance_eval do
    tracked_methods.each do |method_name|
      original_method = instance_method(method_name)
      track           = instance_method(:track)

      define_method(method_name) do |*args, &block|
        track.bind(self).call(:before, method_name, :args => args)
        original_method.bind(self).call(*args, &block).tap do |x|
          track.bind(self).call(:after, method_name, :return => x)
        end
      end
    end
  end
end

Instance Method Details

#log_fileObject



4
5
6
# File 'lib/zeusd/daemon_tracker.rb', line 4

def log_file
  cwd.join('log', 'zeusd.log')
end

#loggerObject



14
15
16
17
18
19
20
# File 'lib/zeusd/daemon_tracker.rb', line 14

def logger
  @logger ||= Logger.new(log_file.to_path).tap do |l|
    l.formatter = proc do |severity, datetime, progname, msg|
      "\e[36m[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}]\e[0m" + " #{msg}\n"
    end
  end
end

#track(occurred, method, details = nil) ⇒ Object



8
9
10
11
12
# File 'lib/zeusd/daemon_tracker.rb', line 8

def track(occurred, method, details = nil)
  logger.info do
    "\e[35m[Track] [#{occurred.to_s.upcase}] .#{method}()\e[0m" + (details ? " " + JSON.pretty_generate(details) : "")
  end
end