class RorRegiment::BulletLog

Public Class Methods

new(options) click to toggle source
# File lib/ror_regiment/bulletlog.rb, line 9
def initialize(options)
  @metadata = options[:metadata]
  @log_type = options[:log_type]
  @api_key = options[:api_key]
  @api_secret_key = options[:api_secret_key]

  check_type! 'metadata', @metadata, Hash
  check_type! 'log_type', @log_type, String
  check_type! 'api_key', @api_key, String
  check_type! 'api_secret_key', @api_secret_key, String

  @log_route = '/log/'
  options = {
    base_uri: "https://ingest.regiment.tech",
    headers: {
      'api-key': @api_key,
      'api-secret-key': @api_secret_key,
      'content-type': 'application/json'
    }
  }
  @client = Connector.new options
end

Public Instance Methods

log(message, details = {}, level = DEBUG, attributes = {}) click to toggle source
# File lib/ror_regiment/bulletlog.rb, line 32
def log(message, details = {}, level = DEBUG, attributes = {})
  payload = {
    log_message: message,
    log_details: details,
    log_type: @log_type,
    log_level: level,
    metadata: @metadata,
    generated_at: Time.now.to_i,
  }
  payload.merge! attributes

  begin
    response = @client.class.post(@log_route, { body: payload.to_json })
    if response.response.code == '200'
      return true
    end
    puts response.parsed_response
    return false
  rescue Exception => e
    puts e
    return false
  end

end
log_critical(message, details = {}, attributes = {}) click to toggle source
# File lib/ror_regiment/bulletlog.rb, line 73
def log_critical(message, details = {}, attributes = {})
  log message, details, CRITICAL, attributes
end
log_debug(message, details = {}, attributes = {}) click to toggle source
# File lib/ror_regiment/bulletlog.rb, line 65
def log_debug(message, details = {}, attributes = {})
  log message, details, DEBUG, attributes
end
log_error(message, details = {}, attributes = {}) click to toggle source
# File lib/ror_regiment/bulletlog.rb, line 61
def log_error(message, details = {}, attributes = {})
  log message, details, ERROR, attributes
end
log_info(message, details = {}, attributes = {}) click to toggle source
# File lib/ror_regiment/bulletlog.rb, line 57
def log_info(message, details = {}, attributes = {})
  log message, details, INFO, attributes
end
log_warning(message, details = {}, attributes = {}) click to toggle source
# File lib/ror_regiment/bulletlog.rb, line 69
def log_warning(message, details = {}, attributes = {})
  log message, details, WARNING, attributes
end