Class: SemanticLogger::Appender::ElasticsearchHttp
- Inherits:
-
Http
- Object
- Base
- Subscriber
- Http
- SemanticLogger::Appender::ElasticsearchHttp
- Defined in:
- lib/semantic_logger/appender/elasticsearch_http.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Http
#compress, #continue_timeout, #header, #http, #open_timeout, #path, #port, #proxy_url, #read_timeout, #server, #ssl_options, #url, #username
Attributes inherited from Subscriber
#application, #environment, #formatter, #host, #logger, #metrics
Attributes inherited from Base
Instance Method Summary collapse
-
#delete_all(date = Date.today) ⇒ Object
Deletes all log data captured for a day.
-
#initialize(index: "semantic_logger", type: "log", url: "http://localhost:9200", **http_args, &block) ⇒ ElasticsearchHttp
constructor
Create Elasticsearch appender over persistent HTTP(S).
-
#log(log) ⇒ Object
Log to the index for today.
Methods inherited from Http
Methods inherited from Subscriber
#close, #console_output?, #default_formatter, #flush, #level, #should_log?
Methods inherited from Base
#backtrace, #fast_tag, #level, #level=, #measure, #named_tags, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags
Constructor Details
#initialize(index: "semantic_logger", type: "log", url: "http://localhost:9200", **http_args, &block) ⇒ ElasticsearchHttp
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.
Deprecated in Elasticsearch 7.0.0
Default: 'log'
level: [:trace | :debug | :info | :warn | :error | :fatal]
Override the log level for this appender.
Default: SemanticLogger.default_level
formatter: [Object|Proc|Symbol|Hash]
An instance of a class that implements #call, or a Proc to be used to format
the output from this appender
Default: Use the built-in formatter (See: #call)
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.
host: [String]
Name of this host to appear in log .
Default: SemanticLogger.host
application: [String]
Name of this application to appear in log .
Default: SemanticLogger.application
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/semantic_logger/appender/elasticsearch_http.rb', line 54 def initialize(index: "semantic_logger", type: "log", url: "http://localhost:9200", **http_args, &block) @index = index @type = type super(url: url, **http_args, &block) @request_path = "#{@path.end_with?('/') ? @path : "#{@path}/"}#{@index}-%Y.%m.%d" @logging_path = "#{@request_path}/#{type}" end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
16 17 18 |
# File 'lib/semantic_logger/appender/elasticsearch_http.rb', line 16 def index @index end |
#type ⇒ Object
Returns the value of attribute type.
16 17 18 |
# File 'lib/semantic_logger/appender/elasticsearch_http.rb', line 16 def type @type end |
Instance Method Details
#delete_all(date = Date.today) ⇒ Object
Deletes all log data captured for a day.
74 75 76 |
# File 'lib/semantic_logger/appender/elasticsearch_http.rb', line 74 def delete_all(date = Date.today) delete(date.strftime(@request_path)) end |
#log(log) ⇒ Object
Log to the index for today.
69 70 71 |
# File 'lib/semantic_logger/appender/elasticsearch_http.rb', line 69 def log(log) post(formatter.call(log, self), log.time.strftime(@logging_path)) end |