gelf_redux 3.1.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 +7 -0
- data/.gemtest +0 -0
- data/CHANGELOG +54 -0
- data/CONTRIBUTING.md +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +20 -0
- data/README.md +69 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/benchmarks/notifier.rb +39 -0
- data/gelf.gemspec +70 -0
- data/lib/gelf/logger.rb +64 -0
- data/lib/gelf/notifier.rb +280 -0
- data/lib/gelf/severity.rb +50 -0
- data/lib/gelf/transport/tcp.rb +79 -0
- data/lib/gelf/transport/tcp_tls.rb +129 -0
- data/lib/gelf/transport/udp.rb +41 -0
- data/lib/gelf.rb +16 -0
- data/test/helper.rb +11 -0
- data/test/test_logger.rb +247 -0
- data/test/test_notifier.rb +317 -0
- data/test/test_ruby_sender.rb +28 -0
- data/test/test_severity.rb +9 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 12a992294a97a00260cb881e3070cb3d47017fd7c60159d1795eb6fee4806514
|
4
|
+
data.tar.gz: 99b6aa9c799b284f231017d8d9b6bafee12ab5a81b68ab5611069349defac6d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3b6eba5fc81cfeec6e306e24632568768102b4b395e603801c5c6cf45d560ba1bc7e437ae15f5dd5836dc9781eaa14b70007ba0b0caed1a0299438a93ba0eb9
|
7
|
+
data.tar.gz: d9e2658d0d6a1bc293875f401aaf2d8deffc37436242131ff2c400f6edac4e3cbb43256ea79d04c7440cd12181397c6c8c0e30d8545163e32072c7b9e8f79e94
|
data/.gemtest
ADDED
File without changes
|
data/CHANGELOG
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
3.0.0, 2016-08-21
|
2
|
+
+ Overhaul TCP support
|
3
|
+
+ Include automatic support for Celluloid::IO if available
|
4
|
+
+ Add TLS support to TCP transport
|
5
|
+
- Remove support for ancient Rubygems versions
|
6
|
+
- Remove support for Ruby 1.9.2 (1.9.3 works!)
|
7
|
+
- Remove already-deprecated `host` and `port` methods on GELF::Notifier
|
8
|
+
|
9
|
+
2.0.0, 2016-02-02
|
10
|
+
+ Added GELF TCP support.
|
11
|
+
|
12
|
+
1.3.2, 2011-12-02:
|
13
|
+
* support for rubygems-test.
|
14
|
+
* rescue from more network errors.
|
15
|
+
|
16
|
+
1.3.1, 2011-10-28:
|
17
|
+
+ allow to rescue from network errors.
|
18
|
+
|
19
|
+
1.3.0, 2011-07-27:
|
20
|
+
+ allow to set timestamp manually.
|
21
|
+
|
22
|
+
1.2.0.beta1, 2011-05-23:
|
23
|
+
+ compatibility with GELF specification 1.0:
|
24
|
+
* requires modern graylog2-server and graylog2-web-interface;
|
25
|
+
+ Notifier#default_options, Notifier#default_options=;
|
26
|
+
+ severity (level) threshold;
|
27
|
+
+ automatically set 'file', 'line' and 'timestamp' fields;
|
28
|
+
+ wrappers for GELF::Notifier#notify with severity:
|
29
|
+
+ GELF::Notifier.debug
|
30
|
+
+ GELF::Notifier.info
|
31
|
+
+ GELF::Notifier.warn
|
32
|
+
+ GELF::Notifier.error
|
33
|
+
+ GELF::Notifier.fatal
|
34
|
+
+ GELF::Notifier.unknown
|
35
|
+
+ full compatibility with Ruby Logger and other loggers:
|
36
|
+
+ GELF::Logger#fatal { "Argument 'foo' not given." }
|
37
|
+
+ GELF::Logger#error "Argument #{ @foo } mismatch."
|
38
|
+
+ GELF::Logger#info('initialize') { "Initializing..." }
|
39
|
+
+ GELF::Logger#add(GELF::FATAL) { 'Fatal error!' }
|
40
|
+
+ GELF::Logger#close
|
41
|
+
+ GELF::Logger#level = GELF::INFO
|
42
|
+
+ allow to change severity mapping;
|
43
|
+
+ send messages to receivers in round-robin;
|
44
|
+
* GELF::Notifier#host and #port are attr_readers now and deprecated (were attr_accessor);
|
45
|
+
+ allow to disable file and line collection (GELF::Notifier#collect_file_and_line = false);
|
46
|
+
- deprecated Gelf class removed.
|
47
|
+
|
48
|
+
1.0.2, 2010-11-29:
|
49
|
+
1.0.1, 2010-11-29:
|
50
|
+
- added more tests for chunking in attempt to locate not existing bug.
|
51
|
+
|
52
|
+
1.0.0, 2010-11-10:
|
53
|
+
+ initial stable version;
|
54
|
+
* deprecated Gelf class is still there.
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Please follow [the instructions on graylog.org](https://www.graylog.org/contributing-to-graylog/).
|
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem "shoulda", "~> 2.11.3"
|
5
|
+
# Because of a dependency chain jeweler->github_api->oauth2->rack,
|
6
|
+
# pin the version: Rack 2.0.x doesn't work on < Ruby 2.2
|
7
|
+
gem 'rack', '< 2.0'
|
8
|
+
gem "mocha", "~> 1.1.0"
|
9
|
+
gem "test-unit", "~> 3.2.0"
|
10
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
metaclass (0.0.4)
|
5
|
+
mocha (1.1.0)
|
6
|
+
metaclass (~> 0.0.1)
|
7
|
+
power_assert (0.3.0)
|
8
|
+
rack (1.6.4)
|
9
|
+
shoulda (2.11.3)
|
10
|
+
test-unit (3.2.1)
|
11
|
+
power_assert
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
java
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
mocha (~> 1.1.0)
|
19
|
+
rack (< 2.0)
|
20
|
+
shoulda (~> 2.11.3)
|
21
|
+
test-unit (~> 3.2.0)
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
1.17.3
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010-2016 Lennart Koopmann, Alexey Palazhchenko
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
## GELF (anew) Ruby library
|
2
|
+
This gem is intended to replace the existing and unmaintained gelf-rb https://github.com/graylog-labs/gelf-rb - since
|
3
|
+
the project went silent for a few years and there seems to be no intention in continuing any kind of support
|
4
|
+
(https://github.com/graylog-labs/gelf-rb/issues/93). So we decided to not just fork but set up a new gem.
|
5
|
+
Since we needed support for http(s) transports as well we are mirroring this fork (https://github.com/christianrolle/gelf-rb) instead
|
6
|
+
of the original project because we wanted to keep all of the projects and maintainers history.
|
7
|
+
|
8
|
+
## Versioning
|
9
|
+
|
10
|
+
- 3.1.1 is the latest original gelf-rb version ()
|
11
|
+
- 3.2.0 is the first http(s) supporting version from here https://github.com/christianrolle/gelf-rb
|
12
|
+
- 4.0.0 we do start from here with our versioning, improvements and updates
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
### Gelf::Notifier
|
18
|
+
|
19
|
+
This allows you to sent arbitary messages via UDP to Graylog.
|
20
|
+
|
21
|
+
n = GELF::Notifier.new("localhost", 12201)
|
22
|
+
|
23
|
+
# Send with custom attributes and an additional parameter "foo"
|
24
|
+
n.notify!(:short_message => "foo", :full_message => "something here\n\nbacktrace?!", :_foo => "bar")
|
25
|
+
|
26
|
+
# Pass any object that responds to .to_hash
|
27
|
+
n.notify!(Exception.new)
|
28
|
+
|
29
|
+
The recommended default is to send via UDP but you can choose to send via TCP like this:
|
30
|
+
|
31
|
+
n = GELF::Notifier.new("127.0.0.1", 12201, "LAN", { :protocol => GELF::Protocol::TCP })
|
32
|
+
|
33
|
+
Note that the `LAN` or `WAN` option is ignored for TCP because no chunking happens. (Read below for more information.)
|
34
|
+
|
35
|
+
### Gelf::Logger
|
36
|
+
|
37
|
+
The Gelf::Logger is compatible with the standard Ruby Logger interface and can be used interchangeably.
|
38
|
+
Under the hood it uses Gelf::Notifier to send log messages via UDP to Graylog.
|
39
|
+
|
40
|
+
logger = GELF::Logger.new("localhost", 12201, "WAN", { :facility => "appname" })
|
41
|
+
|
42
|
+
logger.debug "foobar"
|
43
|
+
logger.info "foobar"
|
44
|
+
logger.warn "foobar"
|
45
|
+
logger.error "foobar"
|
46
|
+
logger.fatal "foobar"
|
47
|
+
|
48
|
+
logger << "foobar"
|
49
|
+
|
50
|
+
Then `WAN` or `LAN` option influences the UDP chunk size depending on if you send in your own
|
51
|
+
network (LAN) or on a longer route (i.e. through the internet) and should be set accordingly.
|
52
|
+
|
53
|
+
Since it's compatible with the Logger interface, you can also use it in your Rails application:
|
54
|
+
|
55
|
+
# config/environments/production.rb
|
56
|
+
config.logger = GELF::Logger.new("localhost", 12201, "WAN", { :facility => "appname" })
|
57
|
+
|
58
|
+
### Note on Patches/Pull Requests
|
59
|
+
|
60
|
+
* Fork the project.
|
61
|
+
* Make your feature addition or bug fix.
|
62
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
63
|
+
* Commit, do not mess with rakefile, version, or history.
|
64
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
65
|
+
* Send me a pull request. Bonus points for topic branches.
|
66
|
+
|
67
|
+
## Copyright
|
68
|
+
|
69
|
+
Copyright (c) 2010-2016 Lennart Koopmann and Alexey Palazhchenko. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'ci/reporter/rake/test_unit'
|
5
|
+
rescue LoadError
|
6
|
+
# nothing
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake/testtask'
|
10
|
+
Rake::TestTask.new(:test) do |test|
|
11
|
+
test.libs << 'lib' << 'test'
|
12
|
+
test.pattern = 'test/**/test_*.rb'
|
13
|
+
test.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :test
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'rcov/rcovtask'
|
20
|
+
Rcov::RcovTask.new do |test|
|
21
|
+
test.libs << 'test'
|
22
|
+
test.pattern = 'test/**/test_*.rb'
|
23
|
+
test.rcov_opts << '--exclude gem'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
rescue LoadError => e
|
27
|
+
task :rcov do
|
28
|
+
puts e
|
29
|
+
abort "rcov is not available. Run: gem install rcov"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#require 'rake/rdoctask'
|
34
|
+
#Rake::RDocTask.new do |rdoc|
|
35
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
36
|
+
#
|
37
|
+
# rdoc.rdoc_dir = 'rdoc'
|
38
|
+
# rdoc.title = "gelf #{version}"
|
39
|
+
# rdoc.rdoc_files.include('README*')
|
40
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
+
#end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.0
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
puts "Loading..."
|
4
|
+
|
5
|
+
require 'benchmark'
|
6
|
+
require 'rubygems'
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'gelf'
|
10
|
+
|
11
|
+
puts "Generating random data..."
|
12
|
+
srand(1)
|
13
|
+
RANDOM_DATA = ('A'..'z').to_a
|
14
|
+
k3_message = (1..3*1024).map { RANDOM_DATA[rand(RANDOM_DATA.count)] }.join
|
15
|
+
|
16
|
+
TARGET_HOST = 'localhost'
|
17
|
+
TARGET_PORT = 12201
|
18
|
+
DEFAULT_OPTIONS = { '_host' => 'localhost' }
|
19
|
+
TIMES = 5000
|
20
|
+
|
21
|
+
SHORT_HASH = { 'short_message' => 'message' }
|
22
|
+
LONG_HASH = { 'short_message' => 'message', 'long_message' => k3_message }
|
23
|
+
|
24
|
+
|
25
|
+
notifier_lan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'LAN', DEFAULT_OPTIONS)
|
26
|
+
notifier_wan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'WAN', DEFAULT_OPTIONS)
|
27
|
+
|
28
|
+
# to create mongo collections, etc.
|
29
|
+
notifier_lan.notify!(LONG_HASH)
|
30
|
+
sleep(5)
|
31
|
+
|
32
|
+
puts "Sending #{TIMES} notifications...\n"
|
33
|
+
tms = Benchmark.bm(25) do |b|
|
34
|
+
b.report('lan, short data, 1 chunk ') { TIMES.times { notifier_lan.notify!(SHORT_HASH) } }
|
35
|
+
sleep(5)
|
36
|
+
b.report('lan, long data, 1 chunk ') { TIMES.times { notifier_lan.notify!(LONG_HASH) } }
|
37
|
+
sleep(5)
|
38
|
+
b.report('wan, long data, 2 chunks') { TIMES.times { notifier_wan.notify!(LONG_HASH) } }
|
39
|
+
end
|
data/gelf.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "gelf_redux"
|
3
|
+
s.version = "3.1.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.required_ruby_version = ">= 1.9"
|
7
|
+
s.require_paths = ["lib"]
|
8
|
+
s.authors = ["Alexey Palazhchenko", "Lennart Koopmann", "Zac Sprackett", "Marcus Ilgner", "Sebastian Seidel"]
|
9
|
+
s.date = "2023-06-19"
|
10
|
+
s.description = "Library to send GELF messages to Graylog logging server. Supports plain-text, GELF messages and exceptions via UDP and TCP."
|
11
|
+
s.email = "admins@manet-marketing.de"
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"LICENSE",
|
14
|
+
"README.md"
|
15
|
+
]
|
16
|
+
s.files = [
|
17
|
+
".gemtest",
|
18
|
+
"CHANGELOG",
|
19
|
+
"CONTRIBUTING.md",
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"benchmarks/notifier.rb",
|
27
|
+
"gelf.gemspec",
|
28
|
+
"lib/gelf.rb",
|
29
|
+
"lib/gelf/logger.rb",
|
30
|
+
"lib/gelf/notifier.rb",
|
31
|
+
"lib/gelf/severity.rb",
|
32
|
+
"lib/gelf/transport/tcp.rb",
|
33
|
+
"lib/gelf/transport/tcp_tls.rb",
|
34
|
+
"lib/gelf/transport/udp.rb",
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_logger.rb",
|
37
|
+
"test/test_notifier.rb",
|
38
|
+
"test/test_ruby_sender.rb",
|
39
|
+
"test/test_severity.rb"
|
40
|
+
]
|
41
|
+
s.homepage = "https://github.com/manet-marketing/gelf_redux"
|
42
|
+
s.licenses = ["MIT"]
|
43
|
+
s.rubygems_version = "2.5.1"
|
44
|
+
s.summary = "Library to send GELF messages to Graylog logging server."
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 4
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
51
|
+
s.add_development_dependency(%q<rack>, ["< 2.0"])
|
52
|
+
s.add_development_dependency(%q<mocha>, ["~> 1.1.0"])
|
53
|
+
s.add_development_dependency(%q<test-unit>, ["~> 3.2.0"])
|
54
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
57
|
+
s.add_dependency(%q<rack>, ["< 2.0"])
|
58
|
+
s.add_dependency(%q<mocha>, ["~> 1.1.0"])
|
59
|
+
s.add_dependency(%q<test-unit>, ["~> 3.2.0"])
|
60
|
+
s.add_dependency(%q<json>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.3"])
|
64
|
+
s.add_dependency(%q<rack>, ["< 2.0"])
|
65
|
+
s.add_dependency(%q<mocha>, ["~> 1.1.0"])
|
66
|
+
s.add_dependency(%q<test-unit>, ["~> 3.2.0"])
|
67
|
+
s.add_dependency(%q<json>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/lib/gelf/logger.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module GELF
|
2
|
+
# Methods for compatibility with Ruby Logger.
|
3
|
+
module LoggerCompatibility
|
4
|
+
|
5
|
+
attr_accessor :formatter
|
6
|
+
|
7
|
+
# Use it like Logger#add... or better not to use at all.
|
8
|
+
def add(level, message = nil, progname = nil, &block)
|
9
|
+
progname ||= default_options['facility']
|
10
|
+
message ||= block.call unless block.nil?
|
11
|
+
|
12
|
+
if message.nil?
|
13
|
+
message = progname
|
14
|
+
progname = default_options['facility']
|
15
|
+
end
|
16
|
+
|
17
|
+
message_hash = { 'facility' => progname }
|
18
|
+
|
19
|
+
if message.is_a?(Hash)
|
20
|
+
message.each do |key, value|
|
21
|
+
message_hash[key.to_s] = value.to_s
|
22
|
+
end
|
23
|
+
else
|
24
|
+
message_hash['short_message'] = message.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
if message.is_a?(Exception)
|
28
|
+
message_hash.merge!(self.class.extract_hash_from_exception(message))
|
29
|
+
end
|
30
|
+
|
31
|
+
if message_hash.key?('short_message') && !message_hash['short_message'].empty?
|
32
|
+
notify_with_level(level, message_hash)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Redefines methods in +Notifier+.
|
37
|
+
GELF::Levels.constants.each do |const|
|
38
|
+
method_name = const.downcase
|
39
|
+
|
40
|
+
define_method(method_name) do |progname=nil, &block|
|
41
|
+
const_level = GELF.const_get(const)
|
42
|
+
add(const_level, nil, progname, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
define_method("#{method_name}?") do
|
46
|
+
const_level = GELF.const_get(const)
|
47
|
+
const_level >= level
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def <<(message)
|
52
|
+
notify_with_level(GELF::UNKNOWN, 'short_message' => message)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Graylog2 notifier, compatible with Ruby Logger.
|
57
|
+
# You can use it with Rails like this:
|
58
|
+
# config.logger = GELF::Logger.new("localhost", 12201, "WAN", { :facility => "appname" })
|
59
|
+
# config.colorize_logging = false
|
60
|
+
class Logger < Notifier
|
61
|
+
include LoggerCompatibility
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|