Class: Logbert::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/logbert/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, level, time, pid, content = nil, &content_proc) ⇒ Message

Returns a new instance of Message.



7
8
9
10
11
12
13
14
15
# File 'lib/logbert/message.rb', line 7

def initialize(logger, level, time, pid, content = nil, &content_proc)
  @logger       = logger
  @level        = level
  @time         = time
  @pid          = pid
  
  @content      = content
  @content_proc = content_proc
end

Instance Attribute Details

#content_proc ⇒ Object (readonly)

Returns the value of attribute content_proc.



5
6
7
# File 'lib/logbert/message.rb', line 5

def content_proc
  @content_proc
end

#level ⇒ Object (readonly)

Returns the value of attribute level.



5
6
7
# File 'lib/logbert/message.rb', line 5

def level
  @level
end

#logger ⇒ Object (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/logbert/message.rb', line 5

def logger
  @logger
end

#pid ⇒ Object (readonly)

Returns the value of attribute pid.



5
6
7
# File 'lib/logbert/message.rb', line 5

def pid
  @pid
end

#time ⇒ Object (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/logbert/message.rb', line 5

def time
  @time
end

Class Method Details

.create(logger, level, content = nil, &content_proc) ⇒ Object



17
18
19
# File 'lib/logbert/message.rb', line 17

def self.create(logger, level, content = nil, &content_proc)
  Message.new logger, level, Time.now, Process.pid, content, &content_proc
end

Instance Method Details

#content ⇒ Object

Returns the content. If the content has not been created yet, then call @content_proc and save the value.



23
24
25
26
27
28
29
30
31
# File 'lib/logbert/message.rb', line 23

def content
  @content ||= begin
    if @content_proc
      @content_proc.call.to_s
    else
      ""
    end
  end
end