Sha256: 86b3ef1a2ce4611c8c6bafcf1adee43e66ad0db00deee77e273f7c76344e481e

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

require 'logger'

module RubyApp
  require 'ruby_app/application'
  require 'ruby_app/mixins/delegate_mixin'

  class Log < ::Logger
    extend RubyApp::Mixins::DelegateMixin

    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

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

    def self.get
      @@_log
    end

    def self.open!
      path = RubyApp::Application.options.log_path
      directory = File.dirname(path)
      Dir.mkdir(directory) unless File.exists?(directory)
      @@_log = RubyApp::Log.new(path)
    end

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

    private

      def initialize(path)
        super(path)
      end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
RubyApp-0.0.70 lib/ruby_app/log.rb
RubyApp-0.0.69 lib/ruby_app/log.rb
RubyApp-0.0.68 lib/ruby_app/log.rb
RubyApp-0.0.64 lib/ruby_app/log.rb
RubyApp-0.0.63 lib/ruby_app/log.rb
RubyApp-0.0.62 lib/ruby_app/log.rb