3 class Logger < ::Logger
4 SYSLOG_EQUIVALENTS = {:fatal => :crit,
18 # Instantiate a new Logger object
27 # If Logger.syslog is true then attempt to load the syslog bindings. If syslog
28 # cannot be loaded, then set Logger.syslog to false and continue.
32 return unless Logger.syslog
37 # Ensure that Syslog is open
49 # +watch+ is the String name of the Watch (may be nil if not Watch is applicable)
50 # +level+ is the log level [:debug|:info|:warn|:error|:fatal]
51 # +text+ is the String message
54 def log(watch, level, text)
55 # initialize watch log if necessary
56 self.logs[watch.name] ||= Timeline.new(God::LOG_BUFFER_SIZE_DEFAULT) if watch
58 # push onto capture and timeline for the given watch
60 templog = ::Logger.new(buf)
61 templog.level = Logger::INFO
62 templog.send(level, text % [])
64 @capture.puts(buf.string) if @capture
65 self.logs[watch.name] << [Time.now, buf.string] if watch
69 # send to regular logger
70 self.send(level, text % [])
73 Syslog.send(SYSLOG_EQUIVALENTS[level], text) if Logger.syslog
76 # Get all log output for a given Watch since a certain Time.
77 # +watch_name+ is the String name of the Watch
78 # +since+ is the Time since which to fetch log lines
81 def watch_log_since(watch_name, since)
82 # initialize watch log if necessary
83 self.logs[watch_name] ||= Timeline.new(God::LOG_BUFFER_SIZE_DEFAULT)
85 # get and join lines since given time
87 self.logs[watch_name].select do |x|
97 # Enable capturing of log
101 @mutex.synchronize do
102 @capture = StringIO.new
106 # Disable capturing of log and return what was captured since
107 # capturing was enabled with Logger#start_capture
111 @mutex.synchronize do
112 cap = @capture.string