Class: RubyApp::Log

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

Defined Under Namespace

Classes: Formatter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::ConfigurationMixin

configuration

Methods included from Mixins::DelegateMixin

exists?, method_missing

Class Method Details

.close!Object



70
71
72
73
74
75
# File 'lib/ruby_app/log.rb', line 70

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

.getObject



58
59
60
# File 'lib/ruby_app/log.rb', line 58

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

.open!Object



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

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



54
55
56
# File 'lib/ruby_app/log.rb', line 54

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

Instance Method Details

#duration(severity, message) ⇒ Object



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

def duration(severity, message)
  start = Time.now
  begin
    return yield
  ensure
    self.log(severity, "#{message} #{Time.now - start}s")
  end
end

#exception(severity, exception) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/ruby_app/log.rb', line 44

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

#memory(severity, message) ⇒ Object



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

def memory(severity, message)
  begin
    return yield
  ensure
    GC.start
    count = ObjectSpace.each_object { |item| }
    self.log(severity, "#{message} count=#{count}")
  end
end