Class: Whoopsy::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/whoopsy.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Log

Returns a new instance of Log.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/whoopsy.rb', line 14

def initialize(args={})

  @debug

  opts = Trollop::options(args) do

    banner "#{Whoopsy::VERSION_BANNER}\n\n#{Whoopsy::HELP_TEXT}"
    version Whoopsy::VERSION_BANNER
    opt :verbose, 'Verbose output.', short: 'v'
    opt :debug, 'Display additional debugging information.'

    opt :host, 'Whoops Logger hostname', type: String
    opt :http_open_timeout, 'HTTP open timeout', type: Integer
    opt :http_read_timeout, 'HTTP read timeout', type: Integer
    opt :port, 'Whoops Logger port', type: Integer
    opt :protocol, 'Whoops Logger Protocol', type: String
    opt :proxy_host, 'Proxy Host', type: String
    opt :proxy_pass, 'Proxy Password', type: String
    opt :proxy_port, 'Proxy Port', type: Integer
    opt :proxy_user, 'Proxy Username', type: String
    opt :secure, 'Secure?'

    opt :event_type, 'your_event_type', type: String
    opt :service, 'my_service_name', type: String
    opt :environment, 'development', type: String
    opt :message, 'String to Show in Whoops Event List', type: String
    opt :event_group_identifier, 'String used to assign related events to a group', type: String
    opt :details, 'A JSON string, or @filename which contains JSON', type: String

  end

  @debug = opts[:debug_given] == true

  @config = Whoopsy::Config.new

  # Set the @config attributes based on the opts hash
  Whoopsy::CONFIG_OPTIONS.each do |option|
    next if option == :details
    eval("@config.#{option} = \"#{opts[option]}\"") if opts["#{option}_given".to_sym]
  end

  if opts[:details_given]
    if opts[:details].to_s.start_with? '@'
      @config.details = Crack::JSON.parse(File.open(opts[:details].to_s[1..-1], 'r').read)
    else
      @config.details = Crack::JSON.parse(opts[:details])
    end
  end

  if @config.details == false
    @config.details = "{\"error\":\"unable to parse JSON data from #{opts[:details]}\"}"
  end

  check_required_args

  send_message
end