Class: RubyApp::Log

Inherits:
Logger
  • Object
show all
Extended by:
Mixins::ConfigurationMixin, Mixins::DelegateMixin
Defined in:
lib/ruby_app/log.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::ConfigurationMixin

configuration

Methods included from Mixins::DelegateMixin

method_missing

Class Method Details

.close!Object



61
62
63
64
65
66
# File 'lib/ruby_app/log.rb', line 61

def self.close!
  if @@_log ||= nil
    @@_log.close
    @@_log = nil
  end
end

.getObject



49
50
51
# File 'lib/ruby_app/log.rb', line 49

def self.get
  ( @@_log ||= nil ) || ( @@_standard_log ||= RubyApp::Log.new($stdout) )
end

.open!Object



53
54
55
56
57
58
59
# File 'lib/ruby_app/log.rb', line 53

def self.open!
  unless @@_log ||= nil
    path = String.interpolate { RubyApp::Log.configuration.path }
    FileUtils.mkdir_p(File.dirname(path))
    @@_log = RubyApp::Log.new(path)
  end
end

.prefix(object, method) ⇒ Object



45
46
47
# File 'lib/ruby_app/log.rb', line 45

def self.prefix(object, method)
  return "#{object.is_a?(Class) ? object : object.class}#{object.is_a?(Class) ? '.' : '#'}#{method}"
end

Instance Method Details

#duration(message) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/ruby_app/log.rb', line 15

def duration(message)
  start = Time.now
  begin
    return yield if block_given?
  ensure
    self.debug("#{message} #{Time.now - start}s")
  end
end

#exception(exception) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/ruby_app/log.rb', line 35

def exception(exception)
  self.error('-' * 80)
  self.error("exception=#{exception.class.inspect} #{exception.message}")
  self.error('-' * 80)
  exception.backtrace.each do |line|
    self.error(line)
  end
  self.error('-' * 80)
end

#memory(message) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_app/log.rb', line 24

def memory(message)
  begin
    return yield if block_given?
  ensure
    GC.start
    count = ObjectSpace.each_object { |item| }
    self.debug("#{message}  count=#{count}")
    self.debug("#{message} memory=#{`ps -o rss= -p #{$$}`.to_i}")
  end
end