logging-honeybadger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 80dabe97be19b246b488191e5bd116162821ac3054e7b376725588893ffd2f24
4
+ data.tar.gz: 3bbcf383fef74c6ae93a038a045d2aa644dba148c33e19078f2b63e358fccaeb
5
+ SHA512:
6
+ metadata.gz: 8496fdffd6e063cc83692c222a56dcc808dcbb7e474f09c48f21b66ae5dff9c8321eb3a68784a4ebc0bca218f61e0c407019b0b37cd051808632135033364cfa
7
+ data.tar.gz: 2915c0b645b8bde603b4890567bf8be9b97ce1f4a2be020328cd7322e89ca800c8459cc60fc258a52a588e26cee1101d2c23904e4280444812e87a47bc805946
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Logging Honeybadger
2
+
3
+ [![CI](https://github.com/sshaw/logging-honeybadger/actions/workflows/ci.yml/badge.svg)](https://github.com/sshaw/logging-honeybadger/actions/workflows/ci.yml)
4
+
5
+ Honeybadger appender for [the Logging gem](https://github.com/TwP/logging)
6
+
7
+ ## Overview
8
+
9
+ Install the gem: `gem install logging-honeybadger`.
10
+
11
+ If you're using Bundler add the following to your `Gemfile`: `gem "logging-honeybadger", :require => false`
12
+
13
+ Then add the Honeybadger appender:
14
+
15
+ ```rb
16
+ require "logging"
17
+
18
+ log = Logging.logger[self]
19
+ log.add_appenders(
20
+ Logging.appenders.honeybadger(
21
+ :api_key => "123XYZ",
22
+ :exceptions => { :ignore => %w[SomeThang AnotherThang] }
23
+ )
24
+ )
25
+
26
+ # Or
27
+
28
+ Honeybadger.configure do |cfg|
29
+ # ...
30
+ end
31
+
32
+ log.add_appenders(Logging.appenders.honeybadger)
33
+
34
+ log.info "Not sent to honeybadger"
35
+ log.error "Honeybadger here I come!"
36
+ log.error SomeError.new("See you @ app.honeybadger.io!")
37
+ ```
38
+
39
+ Note that Logging will load the appender. You do not need to explicitly require it.
40
+
41
+ ## Description
42
+
43
+ Only events with the `:error` log level are sent to Honeybadger.
44
+ By default the appender will be named `"honeybadger"`. This can be changed by passing a name
45
+ to the `honeybadger` method:
46
+
47
+ Logging.appenders.honeybadger("another_name", options)
48
+
49
+ Honeybadger configuration can be done via `Honeybadger.configure` or via `Logging.appenders.honeybadger`.
50
+ The later accepts (most) Honeybadger options via the `options` `Hash`.
51
+
52
+ ## See Also
53
+
54
+ [`Logging::Appenders::Airbrake`](https://github.com/sshaw/logging-appenders-airbrake) - Airbrake appender for the Logging gem
55
+
56
+ ## Author
57
+
58
+ Skye Shaw [sshaw AT gmail.com]
59
+
60
+ ## License
61
+
62
+ Released under the MIT License: www.opensource.org/licenses/MIT
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ # Only with 5.19 and only >= 2.7
3
+ # require "minitest/test_task"
4
+ # Minitest::TestTask.create
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new
8
+
9
+ task :default => :test
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logging"
4
+ require "honeybadger"
5
+
6
+ module Logging
7
+ module Appenders
8
+ def self.honeybadger(*args)
9
+ if args.empty?
10
+ return self[Appenders::Honeybadger::DEFAULT_NAME] || Appenders::Honeybadger.new
11
+ end
12
+
13
+ Appenders::Honeybadger.new(*args)
14
+ end
15
+
16
+ class Honeybadger < Logging::Appender
17
+ VERSION = "0.0.1"
18
+ DEFAULT_NAME = "honeybadger"
19
+
20
+ # Prevent infinite recursion if this logger is assigned to the Honeybadger logger and it logs errors
21
+ INTERNAL_BT_FILTER = %r{honeybadger-[^/]+/lib/honeybadger/}
22
+
23
+ # Remove calls to this class in the stacktrace sent to Honeybadger.
24
+ # Only used when logging a String message.
25
+ HONEYBADGER_BT_FILTER = %r{/logging-[^/]+/lib/logging/}
26
+
27
+ # Can't use respond_to?: https://github.com/honeybadger-io/honeybadger-ruby/issues/481
28
+ HONEYBADGER_SIMPLE_OPTIONS = %i[
29
+ api_key
30
+ controller
31
+ env
32
+ error_class
33
+ report_data
34
+ root
35
+ revision
36
+ hostname
37
+ backend
38
+ debug
39
+ send_data_at_exit
40
+ max_queue_size
41
+ config_path
42
+ development_environments
43
+ plugins
44
+ skipped_plugins
45
+ ].freeze
46
+
47
+ HONEYBADGER_NESTED_OPTIONS = %i[
48
+ breadcrumbs
49
+ connection
50
+ delayed_job
51
+ exceptions
52
+ logging
53
+ rails
54
+ request
55
+ sidekiq
56
+ ].freeze
57
+
58
+ HONEYBADGER_OPTIONS = (HONEYBADGER_SIMPLE_OPTIONS + HONEYBADGER_NESTED_OPTIONS).freeze
59
+
60
+ def initialize(*args)
61
+ args.compact!
62
+
63
+ appender = { :level => :error }
64
+
65
+ name = args.first.is_a?(String) ? args.shift : DEFAULT_NAME
66
+ honeybadger = args.last.is_a?(Hash) ? args.pop.dup : {}
67
+
68
+ ::Honeybadger.configure do |cfg|
69
+ honeybadger.keys.each do |name|
70
+ if HONEYBADGER_OPTIONS.include?(name)
71
+ set_honeybadger_option(cfg, name, honeybadger[name])
72
+ else
73
+ appender[name] = honeybadger.delete(name)
74
+ end
75
+ end
76
+ end
77
+
78
+ super(name, appender)
79
+ end
80
+
81
+ private
82
+
83
+ def set_honeybadger_option(cfg, name, value)
84
+ if HONEYBADGER_SIMPLE_OPTIONS.include?(name)
85
+ cfg.public_send("#{name}=", value)
86
+ return
87
+ end
88
+
89
+ raise ArgumentError, "Nested option #{name}'s value must be a Hash, got #{value.class}" unless value.is_a?(Hash)
90
+
91
+ obj = cfg.public_send(name)
92
+ value.each do |method, v|
93
+ setter = "#{method}="
94
+ if obj.public_send(method).is_a?(Array)
95
+ obj.public_send(setter, obj.public_send(method) + Array(v))
96
+ else
97
+ obj.public_send(setter, v)
98
+ end
99
+ end
100
+ end
101
+
102
+ def write(event)
103
+ return self if caller.any? { |bt| bt =~ INTERNAL_BT_FILTER }
104
+
105
+ # Docs say event can be a String too, not sure when/how but we'll check anyways
106
+ error = event.is_a?(Logging::LogEvent) ? event.data : event
107
+
108
+ options = {}
109
+ options[:context] = Logging.mdc.context if Logging.mdc.context.any?
110
+
111
+ if error.is_a?(Exception)
112
+ options[:backtrace] = error.backtrace
113
+ else
114
+ options[:backtrace] = caller.reject { |line| line =~ HONEYBADGER_BT_FILTER }
115
+ end
116
+
117
+ ::Honeybadger.notify(error, options)
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Logging
4
+ module Plugins
5
+ module Honeybadger
6
+ VERSION = "0.0.1"
7
+
8
+ def self.initialize_honeybadger
9
+ require File.expand_path("../../appenders/honeybadger", __FILE__)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "logging-honeybadger"
5
+ spec.version = "0.0.1"
6
+ spec.authors = ["Skye Shaw"]
7
+ spec.email = ["skye.shaw@gmail.com"]
8
+
9
+ spec.summary = %q{Honeybadger appender for the Logging gem}
10
+ spec.description = %q{An appender for the Logging gem that sends all messages logged at the :error level to Honeybadger}
11
+ spec.homepage = "https://github.com/sshaw/logging-honeybadger"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = ">= 2.4.0"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/sshaw/logging-honeybadger"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
+ end
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Maybe less, but only tested with v5
30
+ spec.add_dependency "honeybadger", "~> 5.0"
31
+ spec.add_dependency "logging"
32
+ spec.add_development_dependency "bundler"
33
+ spec.add_development_dependency "rake"
34
+ spec.add_development_dependency "minitest", "~> 5.0", "<5.16"
35
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logging-honeybadger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Skye Shaw
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: honeybadger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logging
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '5.16'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '5.0'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.16'
89
+ description: An appender for the Logging gem that sends all messages logged at the
90
+ :error level to Honeybadger
91
+ email:
92
+ - skye.shaw@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - Gemfile
98
+ - README.md
99
+ - Rakefile
100
+ - lib/logging/appenders/honeybadger.rb
101
+ - lib/logging/plugins/honeybadger.rb
102
+ - logging-honeybadger.gemspec
103
+ homepage: https://github.com/sshaw/logging-honeybadger
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ homepage_uri: https://github.com/sshaw/logging-honeybadger
108
+ source_code_uri: https://github.com/sshaw/logging-honeybadger
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.4.0
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.1.4
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Honeybadger appender for the Logging gem
128
+ test_files: []