Module: Tailog::WatchMethods

Included in:
Tailog
Defined in:
lib/tailog/watch_methods.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.inject_optionsObject

Returns the value of attribute inject_options.



9
10
11
# File 'lib/tailog/watch_methods.rb', line 9

def inject_options
  @inject_options
end

Class Method Details

.loggerObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tailog/watch_methods.rb', line 11

def logger
  return @logger if @logger
  @logger = Logger.new(File.join Tailog.log_path, "watch_methods.log")
  @logger.formatter = proc do |severity, datetime, progname, message|
    content = ""
    content << "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}]"
    content << "[#{Tailog.request_id}]" if Tailog.request_id
    content << " #{severity.rjust(5)}"
    content << " (#{progname})" if progname
    content << ": #{message.gsub(/\n\s*/, " ")}"
    content << "\n"
    content
  end
  @logger
end

Instance Method Details

#cleanup(targets) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tailog/watch_methods.rb', line 54

def cleanup targets
  WatchMethods.logger.debug "Cleanup #{targets}."
  targets.each do |target|
    if target.include? "#"
      cleanup_instance_method target
    elsif target.include? "."
      cleanup_class_method target
    else
      cleanup_constant target
    end
  end
end

#inject(targets, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tailog/watch_methods.rb', line 36

def inject targets, options = {}
  WatchMethods.logger.debug "Inject #{targets} with options #{options}."
  options = Tailog::WatchMethods.inject_options.merge(options)
  targets.each do |target|
    begin
      if target.include? "#"
        inject_instance_method target, options
      elsif target.include? "."
        inject_class_method target, options
      else
        inject_constant target, options
      end
    rescue => error
      WatchMethods.logger.error "Inject #{target} FAILED: #{error.class}: #{error.message}."
    end
  end
end