Class: Fluent::Logger::EventTime

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/logger/fluent_logger.rb

Constant Summary collapse

TYPE =
0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sec, nsec = 0) ⇒ EventTime

Returns a new instance of EventTime.



32
33
34
35
# File 'lib/fluent/logger/fluent_logger.rb', line 32

def initialize(sec, nsec = 0)
  @sec = sec
  @nsec = nsec
end

Class Method Details

.from_msgpack_ext(data) ⇒ Object



45
46
47
# File 'lib/fluent/logger/fluent_logger.rb', line 45

def self.from_msgpack_ext(data)
  new(*data.unpack('NN'))
end

Instance Method Details

#as_json(*args) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/fluent/logger/fluent_logger.rb', line 53

def as_json(*args)
  # For ActiveSupport.
  # By default, the custom classes are represented by their own instance variables.
  # https://github.com/rails/rails/blob/87a9fdeef81f293cd972464686a6b4470ec642a2/activesupport/lib/active_support/core_ext/object/json.rb#L63
  # Define it in a way that results in proper data structure when expressed in JSON
  @sec
end

#to_json(*args) ⇒ Object



49
50
51
# File 'lib/fluent/logger/fluent_logger.rb', line 49

def to_json(*args)
  @sec.to_s
end

#to_msgpack(io = nil) ⇒ Object



37
38
39
# File 'lib/fluent/logger/fluent_logger.rb', line 37

def to_msgpack(io = nil)
  @sec.to_msgpack(io)
end

#to_msgpack_ext ⇒ Object



41
42
43
# File 'lib/fluent/logger/fluent_logger.rb', line 41

def to_msgpack_ext
  [@sec, @nsec].pack('NN')
end