Class: SemanticLogger::Appender::Elasticsearch
- Defined in:
- lib/semantic_logger/appender/elasticsearch.rb
Overview
SemanticLogger.add_appender(appender)
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Http
#application, #compress, #header, #host, #http, #path, #port, #server, #ssl_options, #url, #username
Attributes inherited from Base
Attributes inherited from Base
Instance Method Summary collapse
-
#delete_all(date = Date.today) ⇒ Object
Deletes all log data captured for a day.
-
#initialize(options, &block) ⇒ Elasticsearch
constructor
Create Elasticsearch appender over persistent HTTP(S).
-
#log(log) ⇒ Object
Log to the index for today.
Methods inherited from Http
Methods inherited from Base
colorized_formatter, #default_formatter, #flush, json_formatter, #level
Methods inherited from Base
#benchmark, default_level, default_level=, #fast_tag, #level, #level=, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload
Constructor Details
#initialize(options, &block) ⇒ Elasticsearch
Create Elasticsearch appender over persistent HTTP(S)
Parameters:
index: [String]
Prefix of the index to store the logs in Elasticsearch.
The final index appends the date so that indexes are used per day.
I.e. The final index will look like 'semantic_logger-YYYY.MM.DD'
Default: 'semantic_logger'
type: [String]
Document type to associate with logs when they are written.
Default: 'log'
level: [:trace | :debug | :info | :warn | :error | :fatal]
Override the log level for this appender.
Default: SemanticLogger.default_level
filter: [Regexp|Proc]
RegExp: Only include log where the class name matches the supplied.
regular expression. All other will be ignored.
Proc: Only include log where the supplied Proc returns true
The Proc must return true or false.
39 40 41 42 43 44 45 46 |
# File 'lib/semantic_logger/appender/elasticsearch.rb', line 39 def initialize(, &block) = .dup @index = .delete(:index) || "semantic_logger" @type = .delete(:type) || 'log' [:url] ||= 'http://localhost:9200' super(, &block) end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
15 16 17 |
# File 'lib/semantic_logger/appender/elasticsearch.rb', line 15 def index @index end |
#type ⇒ Object
Returns the value of attribute type.
15 16 17 |
# File 'lib/semantic_logger/appender/elasticsearch.rb', line 15 def type @type end |
Instance Method Details
#delete_all(date = Date.today) ⇒ Object
Deletes all log data captured for a day
57 58 59 |
# File 'lib/semantic_logger/appender/elasticsearch.rb', line 57 def delete_all(date = Date.today) "#{index}-#{date.strftime('%Y.%m.%d')}/#{type}" end |
#log(log) ⇒ Object
Log to the index for today
49 50 51 52 53 54 |
# File 'lib/semantic_logger/appender/elasticsearch.rb', line 49 def log(log) return false if (level_index > (log.level_index || 0)) || !(log) # Filtered out? post(formatter.call(log, self), "#{index}-#{log.time.strftime('%Y.%m.%d')}/#{type}") end |