Class: RubyApp::Log

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

Defined Under Namespace

Classes: Formatter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::ConfigurationMixin

configuration

Methods included from Mixins::DelegateMixin

exists?, method_missing

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/ruby_app/log.rb', line 17

def path
  @path
end

Class Method Details

.close!Object



73
74
75
76
77
78
79
# File 'lib/ruby_app/log.rb', line 73

def self.close!
  if @@_log ||= nil
    RubyApp::Log.debug("LOG       #{RubyApp::Log.prefix(self, __method__)}")
    @@_log.close
    @@_log = nil
  end
end

.getObject



60
61
62
# File 'lib/ruby_app/log.rb', line 60

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

.open!Object



64
65
66
67
68
69
70
71
# File 'lib/ruby_app/log.rb', line 64

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

.prefix(object, method) ⇒ Object



56
57
58
# File 'lib/ruby_app/log.rb', line 56

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

.reopen!Object



81
82
83
84
# File 'lib/ruby_app/log.rb', line 81

def self.reopen!
  RubyApp::Log.close!
  RubyApp::Log.open!
end

Instance Method Details

#duration(severity, message) ⇒ Object



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

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



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

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



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

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