Class: VCAP::Logging::LogRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/vcap/logging/log_record.rb

Constant Summary collapse

@@have_fibers =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_level, data, logger, tags = []) ⇒ LogRecord

Returns a new instance of LogRecord.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vcap/logging/log_record.rb', line 47

def initialize(log_level, data, logger, tags=[])
  @timestamp   = Time.now
  @data        = data
  @logger_name = logger.name
  @log_level   = log_level
  @tags        = tags

  @thread_id      = Thread.current.object_id
  @thread_shortid = shortid(@thread_id)
  @fiber_id       = LogRecord.current_fiber_id
  @fiber_shortid  = @fiber_id ? shortid(@fiber_id) : nil
  @process_id     = Process.pid
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



37
38
39
# File 'lib/vcap/logging/log_record.rb', line 37

def data
  @data
end

#fiber_idObject (readonly)

Returns the value of attribute fiber_id.



43
44
45
# File 'lib/vcap/logging/log_record.rb', line 43

def fiber_id
  @fiber_id
end

#fiber_shortidObject (readonly)

Returns the value of attribute fiber_shortid.



44
45
46
# File 'lib/vcap/logging/log_record.rb', line 44

def fiber_shortid
  @fiber_shortid
end

#log_levelObject (readonly)

Returns the value of attribute log_level.



38
39
40
# File 'lib/vcap/logging/log_record.rb', line 38

def log_level
  @log_level
end

#logger_nameObject (readonly)

Returns the value of attribute logger_name.



39
40
41
# File 'lib/vcap/logging/log_record.rb', line 39

def logger_name
  @logger_name
end

#process_idObject (readonly)

Returns the value of attribute process_id.



45
46
47
# File 'lib/vcap/logging/log_record.rb', line 45

def process_id
  @process_id
end

#tagsObject (readonly)

Returns the value of attribute tags.



40
41
42
# File 'lib/vcap/logging/log_record.rb', line 40

def tags
  @tags
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



41
42
43
# File 'lib/vcap/logging/log_record.rb', line 41

def thread_id
  @thread_id
end

#thread_shortidObject (readonly)

Returns the value of attribute thread_shortid.



42
43
44
# File 'lib/vcap/logging/log_record.rb', line 42

def thread_shortid
  @thread_shortid
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



36
37
38
# File 'lib/vcap/logging/log_record.rb', line 36

def timestamp
  @timestamp
end

Class Method Details

.current_fiber_idObject



26
27
28
29
30
31
32
# File 'lib/vcap/logging/log_record.rb', line 26

def current_fiber_id
  if have_fibers?
    Fiber.current.object_id
  else
    nil
  end
end

.have_fibers?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vcap/logging/log_record.rb', line 13

def have_fibers?
  if @@have_fibers == nil
    begin
      require 'fiber'
      @@have_fibers = true
    rescue LoadError
      @@have_fibers = false
    end
  else
    @@have_fibers
  end
end