logging-riemann 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82ebed909685ccfca757fb4fecdb41547845903b
4
+ data.tar.gz: 476888e20eceffd733d63b5cdb6d3a6b24fc6d9f
5
+ SHA512:
6
+ metadata.gz: 48267f6fa1c0df692cff7dbf7fe1408d1c27fe6513e60f06c7629d296986f2f1fea472312abe07961d83375f627112c2e7d4b1fdf3554f147bcd424f20cc7c38
7
+ data.tar.gz: 02912a4dc47dc5c67f5547006be9cb6dc2027f1faf8b9d08edb87c968599e393c73226b18541d7bbe2301b6f53bc4c54f568ea781743618114c2309eb6a2ff29
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logging-riemann.gemspec
4
+
5
+
6
+ group :development do
7
+ gem "logging", "1.8.1"
8
+ gem "rspec", "3.1.0"
9
+ gem "timecop", "~> 0.7.1"
10
+ end
11
+
12
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Peter Schrammel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Logging::Riemann
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'logging-riemann'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install logging-riemann
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/logging-riemann/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,84 @@
1
+ require 'uri'
2
+ require 'socket'
3
+
4
+ module Logging
5
+ module Appenders
6
+ def self.riemann(*args)
7
+ return Logging::Appenders::Riemann if args.empty?
8
+ Logging::Appenders::Riemann.new(*args)
9
+ end
10
+
11
+
12
+ class Riemann < Logging::Appender
13
+ DEFAULT_URI = "udp://localhost:5555"
14
+ # @param option accepts :uri like "udp://host:port", :host
15
+ attr_reader :riemann_port, :riemann_host, :riemann_client
16
+
17
+ def initialize(name,options={})
18
+ uri=URI.parse(options[:uri] || DEFAULT_URI)
19
+ @mapper=options[:mapper] || lambda do |hash|
20
+ end
21
+ @riemann_host= uri.host
22
+ @riemann_port = uri.port
23
+ @riemann_client=::Riemann::Client.new(:host => @riemann_host,
24
+ :port => @riemann_port)
25
+ @host=options.delete(:host) || Socket.gethostname
26
+ super
27
+ end
28
+
29
+
30
+ def write(event)
31
+ self.riemann_client << event2riemann_hash(event)
32
+ end
33
+
34
+ def event2riemann_hash(logging_event)
35
+ riemann_event=if logging_event.data.kind_of?(Hash)
36
+ logging_event.data.dup
37
+ else
38
+ {:description => msg2str(logging_event.data)}
39
+ end
40
+
41
+
42
+ @mapper.call(riemann_event)
43
+ riemann_event[:sate] ||= ::Logging::LNAMES[logging_event.level]
44
+ riemann_event[:host] ||= @host
45
+ riemann_event[:service] ||= @name
46
+ riemann_event[:description] ||= logging_event.data[:message]
47
+ riemann_event[:time] ||= logging_event.time.to_i
48
+
49
+ #we don't overrdide given things from any context (mdc/ndc)
50
+ Logging.mdc.context.each do |key, value|
51
+ riemann_event[key] ||= value
52
+ end
53
+
54
+ Logging.ndc.context.each do |ctx|
55
+ if ctx.respond_to?(:each)
56
+ ctx.each do |key, value|
57
+ riemann_event[key] ||= value
58
+ end
59
+ else
60
+ riemann_event[ctx] ||= true #
61
+ end
62
+ end
63
+
64
+ riemann_event
65
+ end
66
+
67
+ def msg2str(msg)
68
+ case msg
69
+ when ::String
70
+ msg
71
+ when ::Exception
72
+ "#{ msg.message } (#{ msg.class })\n" <<
73
+ (msg.backtrace || []).join("\n")
74
+ else
75
+ msg.inspect
76
+ end
77
+ end
78
+
79
+
80
+ end
81
+
82
+
83
+ end
84
+ end
@@ -0,0 +1,9 @@
1
+ require "logging"
2
+ require 'riemann/client'
3
+
4
+ require 'logging/appender'
5
+ require "logging/riemann/version"
6
+ require 'logging/appenders/riemann'
7
+
8
+
9
+
@@ -0,0 +1,5 @@
1
+ module Logging
2
+ module Riemann
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logging-riemann"
8
+ spec.version = "0.0.1" #Logging::Riemann::VERSION
9
+ spec.authors = ["Peter Schrammel"]
10
+ spec.email = ["peter.schrammel@preisanalytics.de"]
11
+ spec.summary = %q{Logs to riemann}
12
+ spec.description = %q{Logs to riemann}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "logging", "~> 1.8.1"
24
+ spec.add_dependency "riemann-client", ">= 0.2.5"
25
+ end
@@ -0,0 +1,54 @@
1
+ RSpec.describe Logging::Appenders::Riemann do
2
+ before do
3
+ @now=Timecop.freeze(Time.local(2014, 12, 10, 10, 20, 19))
4
+ Logging.mdc.clear
5
+ Logging.ndc.clear
6
+ end
7
+
8
+ it "registers the riemann appender" do
9
+ expect(Logging::Appenders.riemann("metric")).to be_kind_of(Logging::Appenders::Riemann)
10
+ end
11
+ it "parses a uri" do
12
+ logger=Logging::Appenders::Riemann.new("metric",:uri => "udp://myhost:5554")
13
+ expect(logger.riemann_host).to eq("myhost")
14
+ expect(logger.riemann_port).to eq(5554)
15
+ end
16
+ it "has a default uri" do
17
+ logger=Logging::Appenders::Riemann.new("metric")
18
+ expect(logger.riemann_host).to eq("localhost")
19
+ expect(logger.riemann_port).to eq(5555)
20
+ end
21
+
22
+ describe "event" do
23
+ let(:appender) do
24
+ Logging::Appenders::Riemann.new("metric",:host => "myhost")
25
+ end
26
+ let(:logger) {
27
+ log = Logging.logger['example_logger']
28
+ log.add_appenders(appender)
29
+ log.level = :info
30
+ log
31
+ }
32
+
33
+ it "creates a hash for event" do
34
+ hash=appender.event2riemann_hash(Logging::LogEvent.new("test",1,{:arg => "value"},false))
35
+ expect(hash).to eq(:arg=>"value",
36
+ :sate=>"INFO",
37
+ :host=>"myhost",
38
+ :service=>"metric",
39
+ :description=>nil,
40
+ :time=>@now.to_i)
41
+ end
42
+
43
+ it "create a reimann event" do
44
+ expect(appender.riemann_client).to receive(:<<).
45
+ with({:description=>"wooha",
46
+ :sate=>"INFO",
47
+ :host=>"myhost",
48
+ :service=>"metric",
49
+ :time=>@now.to_i})
50
+ logger.info("wooha")
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,95 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+
17
+ require 'timecop'
18
+ require 'logging'
19
+ require 'logging/riemann'
20
+ Logging.init(:DEBUG,:INFO,:HAPPY,:WARN,:FATAL)
21
+
22
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
23
+ RSpec.configure do |config|
24
+ # rspec-expectations config goes here. You can use an alternate
25
+ # assertion/expectation library such as wrong or the stdlib/minitest
26
+ # assertions if you prefer.
27
+ config.expect_with :rspec do |expectations|
28
+ # This option will default to `true` in RSpec 4. It makes the `description`
29
+ # and `failure_message` of custom matchers include text for helper methods
30
+ # defined using `chain`, e.g.:
31
+ # be_bigger_than(2).and_smaller_than(4).description
32
+ # # => "be bigger than 2 and smaller than 4"
33
+ # ...rather than:
34
+ # # => "be bigger than 2"
35
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
36
+ end
37
+
38
+ # rspec-mocks config goes here. You can use an alternate test double
39
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
40
+ config.mock_with :rspec do |mocks|
41
+ # Prevents you from mocking or stubbing a method that does not exist on
42
+ # a real object. This is generally recommended, and will default to
43
+ # `true` in RSpec 4.
44
+ mocks.verify_partial_doubles = true
45
+ end
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # These two settings work together to allow you to limit a spec run
51
+ # to individual examples or groups you care about by tagging them with
52
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
+ # get run.
54
+ config.filter_run :focus
55
+ config.run_all_when_everything_filtered = true
56
+
57
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
58
+ # For more details, see:
59
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
60
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
62
+ config.disable_monkey_patching!
63
+
64
+ # This setting enables warnings. It's recommended, but in some cases may
65
+ # be too noisy due to issues in dependencies.
66
+ config.warnings = true
67
+
68
+ # Many RSpec users commonly either run the entire suite or an individual
69
+ # file, and it's useful to allow more verbose output when running an
70
+ # individual spec file.
71
+ if config.files_to_run.one?
72
+ # Use the documentation formatter for detailed output,
73
+ # unless a formatter has already been configured
74
+ # (e.g. via a command-line flag).
75
+ config.default_formatter = 'doc'
76
+ end
77
+
78
+ # Print the 10 slowest examples and example groups at the
79
+ # end of the spec run, to help surface which specs are running
80
+ # particularly slow.
81
+ config.profile_examples = 10
82
+
83
+ # Run specs in random order to surface order dependencies. If you find an
84
+ # order dependency and want to debug it, you can fix the order by providing
85
+ # the seed, which is printed after each run.
86
+ # --seed 1234
87
+ config.order = :random
88
+
89
+ # Seed global randomization in this process using the `--seed` CLI option.
90
+ # Setting this allows you to use `--seed` to deterministically reproduce
91
+ # test failures related to randomization by passing the same `--seed` value
92
+ # as the one that triggered the failure.
93
+ Kernel.srand config.seed
94
+ =end
95
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logging-riemann
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Schrammel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: logging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: riemann-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.5
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.5
69
+ description: Logs to riemann
70
+ email:
71
+ - peter.schrammel@preisanalytics.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/logging/appenders/riemann.rb
83
+ - lib/logging/riemann.rb
84
+ - lib/logging/riemann/version.rb
85
+ - logging-riemann.gemspec
86
+ - spec/lib/appenders/riemann_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Logs to riemann
112
+ test_files:
113
+ - spec/lib/appenders/riemann_spec.rb
114
+ - spec/spec_helper.rb