Class: Backup::Logger::Message

Inherits:
Struct
  • Object
show all
Defined in:
lib/backup/logger.rb

Overview

All messages sent to the Logger are stored in Logger.messages and sent to all enabled logger’s #log method as Message objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#levelObject

Returns the value of attribute level

Returns:

  • (Object)

    the current value of level



40
41
42
# File 'lib/backup/logger.rb', line 40

def level
  @level
end

#linesObject

Returns the value of attribute lines

Returns:

  • (Object)

    the current value of lines



40
41
42
# File 'lib/backup/logger.rb', line 40

def lines
  @lines
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



40
41
42
# File 'lib/backup/logger.rb', line 40

def time
  @time
end

Instance Method Details

#formatted_linesObject

Returns an Array of the message lines in the following format:

[YYYY/MM/DD HH:MM:SS][level] message line text


45
46
47
48
# File 'lib/backup/logger.rb', line 45

def formatted_lines
  timestamp = time.strftime("%Y/%m/%d %H:%M:%S")
  lines.map {|line| "[#{ timestamp }][#{ level }] #{ line }" }
end

#matches?(ignores) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/backup/logger.rb', line 50

def matches?(ignores)
  text = lines.join("\n")
  ignores.any? {|obj|
    obj.is_a?(Regexp) ? text.match(obj) : text.include?(obj)
  }
end