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, exception, options, content = nil, &content_proc) ⇒ Message

Returns a new instance of Message.



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

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

Instance Attribute Details

#content_procObject (readonly)

Returns the value of attribute content_proc.



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

def content_proc
  @content_proc
end

#exceptionObject (readonly)

Returns the value of attribute exception.



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

def exception
  @exception
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pidObject (readonly)

Returns the value of attribute pid.



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

def pid
  @pid
end

#timeObject (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, exception, options, content = nil, &content_proc) ⇒ Object



19
20
21
# File 'lib/logbert/message.rb', line 19

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

Instance Method Details

#contentObject

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



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

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