Class: Alerty::Plugin::Stackdriver
- Inherits:
-
Object
- Object
- Alerty::Plugin::Stackdriver
- Defined in:
- lib/alerty/plugin/stackdriver.rb
Constant Summary collapse
- DEFAULT_NUM_OF_RETIRES =
3
Instance Method Summary collapse
- #alert(record) ⇒ Object
-
#initialize(config) ⇒ Stackdriver
constructor
A new instance of Stackdriver.
Constructor Details
#initialize(config) ⇒ Stackdriver
Returns a new instance of Stackdriver.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/alerty/plugin/stackdriver.rb', line 10 def initialize(config) # https://cloud.google.com/logging/docs/api/v2/resource-list @resource_type = config.resource_type @resource_labels = config.resource_labels @app_name = config.app_name || 'alerty' @app_version = config.app_version || 'default' @log_name = config.log_name || 'alerty' @message = config. @num_retries = config.num_retries || DEFAULT_NUM_OF_RETIRES @stackdriver = Google::Cloud::Logging.new( project_id: config.project_id, keyfile: config.keyfile ? ensure_keyfile(config.keyfile) : nil ) end |
Instance Method Details
#alert(record) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/alerty/plugin/stackdriver.rb', line 26 def alert(record) entry = make_entry(record) retrable(tries: @num_retries) do @stackdriver.write_entries(entry) Alerty.logger.info "Sent #{{log_entry: entry.inspect}} to #{@log_name}" end end |