logging-appenders-airbrake 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +3 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/lib/logging/appenders/airbrake.rb +63 -0
- data/logging-appenders-airbrake.gemspec +24 -0
- data/test/test_airbrake.rb +69 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e929ba30042809af24030e50fced5b64859fc26b
|
4
|
+
data.tar.gz: 94880fe8ac8fed00c0cffd06b9a46a7c111afe35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb14162f105a6cfaaa72388662bf2050b95773c0cd66ae1f4ac4545b37d5cd3272269e7655f401566edca5212f9246a3da07855d128fffb617b289d53f5cfcc6
|
7
|
+
data.tar.gz: 81da15b60be0f1909fbf6e745d9b8070ae672c54be98c74e89a4baa81373caeb4e3d42183cce95c6c66ff85a5be3c4c6facc5df5d765ac92e164ceb3b19379b7
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Logging::Appenders::Airbrake
|
2
|
+
|
3
|
+
Airbrake appender for [the logging gem](https://github.com/TwP/logging).
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
require "logging"
|
8
|
+
require "logging/appenders/airbrake"
|
9
|
+
|
10
|
+
log = Logging.logger[self]
|
11
|
+
log.add_appenders(
|
12
|
+
Logging.appenders.airbrake(:api_key => "123XYZ", :ignore => %w[SomeThang AnotherThang])
|
13
|
+
)
|
14
|
+
|
15
|
+
# Or
|
16
|
+
|
17
|
+
Airbrake.configure do |cfg|
|
18
|
+
# ...
|
19
|
+
end
|
20
|
+
|
21
|
+
log.add_appenders(Logging.appenders.airbrake)
|
22
|
+
|
23
|
+
log.info "Not sent to airbrake"
|
24
|
+
log.error "Airbrake here I come!"
|
25
|
+
log.error SomeError.new("See you @ airbrake.io!")
|
26
|
+
|
27
|
+
## Description
|
28
|
+
|
29
|
+
Only events with the `:error` log level are sent to Airbrake. Errors are not sent asynchronously,
|
30
|
+
though this can be changed via `Airbrake.configure`.
|
31
|
+
|
32
|
+
By default the appender will be named `"airbrake"`. This can be changed by passing a name
|
33
|
+
to the `airbrake` method:
|
34
|
+
|
35
|
+
Logging.appenders.airbrake("another_name", options)
|
36
|
+
|
37
|
+
Airbrake configuration can be done via `Airbrake.configure` or via `Logging.appenders.airbrake`.
|
38
|
+
All Airbrake options can be passed to the latter.
|
39
|
+
|
40
|
+
## Using With `logging-rails`
|
41
|
+
|
42
|
+
If you're already using Airbrake then your current Airbrake initializer will be used.
|
43
|
+
If not you can either create one or specify your options in `config/logging.rb`.
|
44
|
+
|
45
|
+
In `config/logging.rb`:
|
46
|
+
|
47
|
+
Logging.appenders.airbrake if config.log_to.include?("airbrake")
|
48
|
+
|
49
|
+
In `config/environments/xxx.rb`, where `xxx` corresponds to the desired `Rails.env`:
|
50
|
+
|
51
|
+
config.log_to = %w[airbrake] # or %w[airbrake file email] # etc...
|
52
|
+
|
53
|
+
## Author
|
54
|
+
|
55
|
+
Skye Shaw [sshaw AT gmail.com]
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
Released under the MIT License: www.opensource.org/licenses/MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "airbrake"
|
2
|
+
require "logging/appender"
|
3
|
+
|
4
|
+
module Logging::Appenders
|
5
|
+
def self.airbrake(*args)
|
6
|
+
if args.empty?
|
7
|
+
return self["airbrake"] || Logging::Appenders::Airbrake.new
|
8
|
+
end
|
9
|
+
|
10
|
+
Logging::Appenders::Airbrake.new(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Airbrake < Logging::Appender
|
14
|
+
FILTER = lambda do |line|
|
15
|
+
line =~ %r{/logging-[^/]+/lib/logging/} ? nil : line
|
16
|
+
end
|
17
|
+
|
18
|
+
attr :options
|
19
|
+
|
20
|
+
def initialize(*args)
|
21
|
+
args.compact!
|
22
|
+
|
23
|
+
name = args.first.is_a?(String) ? args.shift : "airbrake"
|
24
|
+
super(name, :level => :error)
|
25
|
+
|
26
|
+
cfg = ::Airbrake.configuration
|
27
|
+
cfg.framework = "Logging #{Logging.version}"
|
28
|
+
|
29
|
+
@options = args.shift || {}
|
30
|
+
@options[:backtrace_filters] ||= []
|
31
|
+
@options[:backtrace_filters] << FILTER
|
32
|
+
|
33
|
+
@options.each do |k,v|
|
34
|
+
unless ::Airbrake::Configuration::OPTIONS.include?(k)
|
35
|
+
raise ArgumentError, "unknown Airbrake configuration option #{k}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Airbrake array attributes have no setter
|
39
|
+
if cfg[k].is_a?(Array)
|
40
|
+
cfg[k].concat(Array(v))
|
41
|
+
else
|
42
|
+
cfg.method("#{k}=")[v]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def write(event)
|
50
|
+
if ::Airbrake.configuration.configured?
|
51
|
+
# Docs say event can be a String too, not sure when/how but we'll check anyways
|
52
|
+
error = event.is_a?(Logging::LogEvent) ? event.data : event
|
53
|
+
error = { :error_message => error } if error.is_a?(String)
|
54
|
+
|
55
|
+
::Airbrake.notify_or_ignore(error)
|
56
|
+
else
|
57
|
+
# TODO: better to just set Airbrake's logger to something so it can log this?
|
58
|
+
Logging.log_internal { 'Not logging #{event.inspect}: Airbrake is not configured' }
|
59
|
+
end
|
60
|
+
self
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "logging-appenders-airbrake"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Skye Shaw"]
|
9
|
+
spec.email = ["skye.shaw@gmail.com"]
|
10
|
+
spec.summary = %q{Airbrake appender for the logging gem}
|
11
|
+
spec.description = %q{An appender for the logging gem that will send all messages logged at the :error level to Airbrake}
|
12
|
+
spec.homepage = "https://github.com/sshaw/logging-appenders-airbrake"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "airbrake"
|
21
|
+
spec.add_dependency "logging"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "minitest/mock"
|
4
|
+
|
5
|
+
require "logging"
|
6
|
+
require "logging/appenders/airbrake"
|
7
|
+
|
8
|
+
class TestAirbrake < MiniTest::Unit::TestCase
|
9
|
+
def test_configuration_without_appender_name
|
10
|
+
app = appender(config)
|
11
|
+
|
12
|
+
refute_nil Logging.logger["airbrake"]
|
13
|
+
assert_same app, Logging.appenders.airbrake
|
14
|
+
|
15
|
+
assert_equal config[:api_key], Airbrake.configuration.api_key
|
16
|
+
assert_equal config[:host], Airbrake.configuration.host
|
17
|
+
config[:ignore].each do |name|
|
18
|
+
assert_includes Airbrake.configuration.ignore, name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_configuration_with_appender_name
|
23
|
+
app = appender("sshaw", config)
|
24
|
+
|
25
|
+
refute_nil Logging.logger["sshaw"]
|
26
|
+
refute_same app, Logging.appenders.airbrake
|
27
|
+
|
28
|
+
assert_equal config[:api_key], Airbrake.configuration.api_key
|
29
|
+
assert_equal config[:host], Airbrake.configuration.host
|
30
|
+
config[:ignore].each do |name|
|
31
|
+
assert_includes Airbrake.configuration.ignore, name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_invalid_configuration
|
36
|
+
assert_raises(ArgumentError, /unknown/) { appender(:ass => "bass") }
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_only_error_level_logged
|
40
|
+
count = 0
|
41
|
+
app = appender
|
42
|
+
app.define_singleton_method(:write) { |e| count += 1 }
|
43
|
+
|
44
|
+
log = Logging.logger[self]
|
45
|
+
log.add_appenders(app)
|
46
|
+
|
47
|
+
log.info("Hi")
|
48
|
+
log.error("Hello hello!")
|
49
|
+
log.error("¡Hola!")
|
50
|
+
log.debug("Oizinho")
|
51
|
+
log.warn("Perigo")
|
52
|
+
|
53
|
+
assert_equal 2, count
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def config
|
58
|
+
@config ||= {
|
59
|
+
:api_key => "X123",
|
60
|
+
:host => "example.com",
|
61
|
+
:ignore => %w[A B]
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def appender(*args)
|
66
|
+
args << { :api_key => "X123" } unless args.last.is_a?(Hash)
|
67
|
+
Logging.appenders.airbrake(*args)
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logging-appenders-airbrake
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Skye Shaw
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: airbrake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '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: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
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
|
+
description: An appender for the logging gem that will send all messages logged at
|
70
|
+
the :error level to Airbrake
|
71
|
+
email:
|
72
|
+
- skye.shaw@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/logging/appenders/airbrake.rb
|
82
|
+
- logging-appenders-airbrake.gemspec
|
83
|
+
- test/test_airbrake.rb
|
84
|
+
homepage: https://github.com/sshaw/logging-appenders-airbrake
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Airbrake appender for the logging gem
|
108
|
+
test_files:
|
109
|
+
- test/test_airbrake.rb
|