Class: EcsFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_log_rails/ecs_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name:, service_type:, service_env:) ⇒ EcsFormatter

Returns a new instance of EcsFormatter.



6
7
8
9
10
# File 'lib/ecs_log_rails/ecs_formatter.rb', line 6

def initialize(service_name:, service_type:, service_env:)
  @service_name = service_name
  @service_env = service_env
  @service_type = service_type
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/ecs_log_rails/ecs_formatter.rb', line 4

def data
  @data
end

#ecs_dataObject (readonly)

Returns the value of attribute ecs_data.



4
5
6
# File 'lib/ecs_log_rails/ecs_formatter.rb', line 4

def ecs_data
  @ecs_data
end

#service_envObject (readonly)

Returns the value of attribute service_env.



4
5
6
# File 'lib/ecs_log_rails/ecs_formatter.rb', line 4

def service_env
  @service_env
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



4
5
6
# File 'lib/ecs_log_rails/ecs_formatter.rb', line 4

def service_name
  @service_name
end

#service_typeObject (readonly)

Returns the value of attribute service_type.



4
5
6
# File 'lib/ecs_log_rails/ecs_formatter.rb', line 4

def service_type
  @service_type
end

Instance Method Details

#call(data) ⇒ Object



12
13
14
15
16
17
# File 'lib/ecs_log_rails/ecs_formatter.rb', line 12

def call(data)
  @data = data
  generate_ecs
  event = LogStash::Event.new(deep_compact(ecs_data))
  event.to_json
end