Class: RubyApp::Log
- Extended by:
- Mixins::ConfigurationMixin, Mixins::DelegateMixin
- Defined in:
- lib/ruby_app/log.rb
Defined Under Namespace
Classes: Formatter
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #duration(severity, message) ⇒ Object
- #exception(severity, exception) ⇒ Object
- #memory(severity, message) ⇒ Object
Methods included from Mixins::ConfigurationMixin
Methods included from Mixins::DelegateMixin
Instance Attribute Details
#path ⇒ Object (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 |
.get ⇒ Object
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 |
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, ) start = Time.now begin return yield ensure self.log(severity, "#{} #{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.}") 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, ) begin return yield ensure GC.start count = ObjectSpace.each_object { |item| } self.log(severity, "#{} #{count} objects") end end |