Module: Docman::Logging

Included in:
Command, Context
Defined in:
lib/docman/logging.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.loggerObject



8
9
10
# File 'lib/docman/logging.rb', line 8

def self.logger
  @logger ||= Logger.new(STDOUT)
end

Instance Method Details

#log(message, type = 'debug') ⇒ Object



33
34
35
# File 'lib/docman/logging.rb', line 33

def log(message, type = 'debug')
  logger.send(type, "#{prefix} - #{message}")
end

#loggerObject



4
5
6
# File 'lib/docman/logging.rb', line 4

def logger
  Logging.logger
end

#prefixObject



37
38
# File 'lib/docman/logging.rb', line 37

def prefix
end

#properties_info(properties = []) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/docman/logging.rb', line 12

def properties_info(properties = [])
  arr = ["name=#{self.class.name}"]
  properties.each do |property|
    if self.is_a? Hash
      arr << "#{property}=#{self[property]}" if self.include?(property)
    else
      arr << "#{property}=#{self.send(property)}" if self.respond_to?(property)
    end
  end
  arr.join(', ')
end

#with_logging(message = nil, type = 'debug') ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/docman/logging.rb', line 24

def with_logging(message = nil, type = 'debug')
  # logger.send(type, "#{prefix} - #{message} - start") if @log
  log("#{message} - start", type)
  result = yield
  log("#{message} - finish", type)
  # logger.send(type, "#{prefix} - #{message} - finish") if @log
  result
end