Module: Logasm::Utils
- Defined in:
- lib/logasm/utils.rb
Constant Summary collapse
- DECIMAL_FRACTION_OF_SECOND =
3
Class Method Summary collapse
-
.application_name(service_name) ⇒ String
Return application name.
-
.build_event(metadata, level, service_name) ⇒ Hash
Build logstash json compatible event.
- .serialize_time_objects(object) ⇒ Object
Class Method Details
.application_name(service_name) ⇒ String
Return application name
Returns lower snake case application name. This allows the application value to be used in the elasticsearch index name.
31 32 33 |
# File 'lib/logasm/utils.rb', line 31 def self.application_name(service_name) Inflecto.underscore(service_name) end |
.build_event(metadata, level, service_name) ⇒ Hash
Build logstash json compatible event
14 15 16 17 18 19 20 21 |
# File 'lib/logasm/utils.rb', line 14 def self.build_event(, level, service_name) overwritable_params .merge(serialize_time_objects()) .merge( application: application_name(service_name), level: level.to_s.downcase ) end |
.serialize_time_objects(object) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/logasm/utils.rb', line 41 def self.serialize_time_objects(object) if object.is_a?(Hash) object.reduce({}) do |hash, (key, value)| hash.merge(key => serialize_time_objects(value)) end elsif object.is_a?(Array) object.map(&method(:serialize_time_objects)) elsif object.is_a?(Time) || object.is_a?(Date) object.iso8601 else object end end |