gelf 1.1.3 → 1.2.0.beta1
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.
- data/CHANGELOG +9 -5
- data/LICENSE +1 -1
- data/README.rdoc +2 -2
- data/Rakefile +48 -13
- data/VERSION +1 -1
- data/benchmarks/notifier.rb +2 -2
- data/gelf.gemspec +26 -40
- data/lib/gelf.rb +0 -1
- data/lib/gelf/logger.rb +9 -6
- data/lib/gelf/notifier.rb +64 -22
- data/lib/gelf/ruby_sender.rb +8 -17
- data/lib/gelf/severity.rb +13 -4
- data/test/helper.rb +0 -5
- data/test/test_logger.rb +54 -50
- data/test/test_notifier.rb +13 -6
- data/test/test_ruby_sender.rb +13 -6
- data/test/test_severity.rb +2 -2
- metadata +24 -25
- data/.gitignore +0 -6
- data/lib/gelf/deprecations.rb +0 -37
- data/lib/gelf/em_sender.rb +0 -19
- data/test/test_deprecations.rb +0 -38
data/CHANGELOG
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0, 2010-0x-yy:
|
2
2
|
+ compatibility with GELF specification 1.0:
|
3
|
-
* requires graylog2-server
|
4
|
-
|
5
|
-
+ Notifier#default_options;
|
3
|
+
* requires modern graylog2-server and graylog2-web-interface;
|
4
|
+
+ Notifier#default_options, Notifier#default_options=;
|
6
5
|
+ severity (level) threshold;
|
7
|
-
+ automatically set '
|
6
|
+
+ automatically set 'file', 'line' and 'timestamp' fields;
|
8
7
|
+ wrappers for GELF::Notifier#notify with severity:
|
9
8
|
+ GELF::Notifier.debug
|
10
9
|
+ GELF::Notifier.info
|
@@ -19,6 +18,11 @@
|
|
19
18
|
+ GELF::Logger#add(GELF::FATAL) { 'Fatal error!' }
|
20
19
|
+ GELF::Logger#close
|
21
20
|
+ GELF::Logger#level = GELF::INFO
|
21
|
+
+ allow to change severity mapping;
|
22
|
+
+ send messages to receivers in round-robin;
|
23
|
+
* GELF::Notifier#host and #port are attr_readers now and deprecated (were attr_accessor);
|
24
|
+
+ allow to disable file and line collection (GELF::Notifier#collect_file_and_line = false);
|
25
|
+
- deprecated Gelf class removed.
|
22
26
|
|
23
27
|
1.0.2, 2010-11-29:
|
24
28
|
1.0.1, 2010-11-29:
|
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= GELF
|
2
2
|
|
3
|
-
This is the new GELF gem written by
|
3
|
+
This is the new GELF gem written by Alexey Palazhchenko. It is based on the old gem by Lennart Koopmann and allows you to send GELF
|
4
4
|
messages to Graylog2 server instances. See http://www.graylog2.org/about/gelf for more information about GELF and
|
5
5
|
http://www.graylog2.org/documentation/libraries for usage examples.
|
6
6
|
|
@@ -17,4 +17,4 @@ Works with Ruby 1.8.7 and 1.9.2. 1.8.6 is not supported.
|
|
17
17
|
|
18
18
|
== Copyright
|
19
19
|
|
20
|
-
Copyright (c) 2010 Lennart Koopmann and
|
20
|
+
Copyright (c) 2010 Lennart Koopmann and Alexey Palazhchenko. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,24 +1,29 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'rake'
|
3
2
|
|
4
3
|
begin
|
5
|
-
|
4
|
+
require 'ci/reporter/rake/test_unit'
|
5
|
+
rescue LoadError
|
6
|
+
# nothing
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
6
10
|
require 'jeweler'
|
11
|
+
|
7
12
|
Jeweler::Tasks.new do |gem|
|
8
13
|
gem.name = "gelf"
|
9
14
|
gem.summary = 'Library to send GELF messages to Graylog2 logging server.'
|
10
15
|
gem.description = 'Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.'
|
11
|
-
gem.email = "
|
16
|
+
gem.email = "alexey.palazhchenko@gmail.com"
|
12
17
|
gem.homepage = "http://github.com/Graylog2/gelf-rb"
|
13
|
-
gem.authors = ["
|
18
|
+
gem.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
|
14
19
|
gem.add_dependency "json"
|
15
20
|
gem.add_development_dependency "shoulda"
|
16
21
|
gem.add_development_dependency "mocha"
|
17
22
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
23
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
rescue LoadError => e
|
25
|
+
puts e
|
26
|
+
abort "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
27
|
end
|
23
28
|
|
24
29
|
require 'rake/testtask'
|
@@ -28,6 +33,9 @@ Rake::TestTask.new(:test) do |test|
|
|
28
33
|
test.verbose = true
|
29
34
|
end
|
30
35
|
|
36
|
+
task :test => :check_dependencies
|
37
|
+
task :default => :test
|
38
|
+
|
31
39
|
begin
|
32
40
|
require 'rcov/rcovtask'
|
33
41
|
Rcov::RcovTask.new do |test|
|
@@ -36,20 +44,47 @@ begin
|
|
36
44
|
test.rcov_opts << '--exclude gem'
|
37
45
|
test.verbose = true
|
38
46
|
end
|
39
|
-
rescue LoadError
|
47
|
+
rescue LoadError => e
|
40
48
|
task :rcov do
|
41
|
-
|
49
|
+
puts e
|
50
|
+
abort "rcov is not available. Run: gem install rcov"
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
45
54
|
begin
|
55
|
+
gem 'ruby_parser', '~> 2.0.6'
|
56
|
+
gem 'activesupport', '~> 3.0.0'
|
57
|
+
gem 'metric_fu', '~> 2.1.1'
|
46
58
|
require 'metric_fu'
|
47
|
-
rescue LoadError
|
48
|
-
end
|
49
59
|
|
50
|
-
|
60
|
+
MetricFu::Configuration.run do |config|
|
61
|
+
# Saikuro is useless
|
62
|
+
config.metrics -= [:saikuro]
|
51
63
|
|
52
|
-
|
64
|
+
config.flay = { :dirs_to_flay => ['lib'],
|
65
|
+
:minimum_score => 10 }
|
66
|
+
config.flog = { :dirs_to_flog => ['lib'] }
|
67
|
+
config.reek = { :dirs_to_reek => ['lib'] }
|
68
|
+
config.roodi = { :dirs_to_roodi => ['lib'] }
|
69
|
+
config.rcov = { :environment => 'test',
|
70
|
+
:test_files => ['test/test_*.rb'],
|
71
|
+
:rcov_opts => ["-I 'lib:test'",
|
72
|
+
"--sort coverage",
|
73
|
+
"--no-html",
|
74
|
+
"--text-coverage",
|
75
|
+
"--no-color",
|
76
|
+
"--exclude /test/,/gems/"]}
|
77
|
+
config.graph_engine = :gchart
|
78
|
+
end
|
79
|
+
|
80
|
+
rescue LoadError, NameError => e
|
81
|
+
desc 'Generate all metrics reports'
|
82
|
+
task :'metrics:all' do
|
83
|
+
puts e.inspect
|
84
|
+
# puts e.backtrace
|
85
|
+
abort "metric_fu is not available. Run: gem install metric_fu"
|
86
|
+
end
|
87
|
+
end
|
53
88
|
|
54
89
|
require 'rake/rdoctask'
|
55
90
|
Rake::RDocTask.new do |rdoc|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0.beta1
|
data/benchmarks/notifier.rb
CHANGED
@@ -18,8 +18,8 @@ TARGET_PORT = 12201
|
|
18
18
|
DEFAULT_OPTIONS = { '_host' => 'localhost' }
|
19
19
|
TIMES = 5000
|
20
20
|
|
21
|
-
SHORT_HASH = { '
|
22
|
-
LONG_HASH = { '
|
21
|
+
SHORT_HASH = { 'short_message' => 'message' }
|
22
|
+
LONG_HASH = { 'short_message' => 'message', 'long_message' => k3_message }
|
23
23
|
|
24
24
|
|
25
25
|
notifier_lan = GELF::Notifier.new(TARGET_HOST, TARGET_PORT, 'LAN', DEFAULT_OPTIONS)
|
data/gelf.gemspec
CHANGED
@@ -1,60 +1,46 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gelf}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0.beta1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Alexey Palazhchenko}, %q{Lennart Koopmann}]
|
12
|
+
s.date = %q{2011-05-23}
|
13
13
|
s.description = %q{Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.}
|
14
|
-
s.email = %q{
|
14
|
+
s.email = %q{alexey.palazhchenko@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
"test/test_logger.rb",
|
38
|
-
"test/test_notifier.rb",
|
39
|
-
"test/test_ruby_sender.rb",
|
40
|
-
"test/test_severity.rb"
|
20
|
+
"CHANGELOG",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"benchmarks/notifier.rb",
|
26
|
+
"gelf.gemspec",
|
27
|
+
"lib/gelf.rb",
|
28
|
+
"lib/gelf/logger.rb",
|
29
|
+
"lib/gelf/notifier.rb",
|
30
|
+
"lib/gelf/ruby_sender.rb",
|
31
|
+
"lib/gelf/severity.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_logger.rb",
|
34
|
+
"test/test_notifier.rb",
|
35
|
+
"test/test_ruby_sender.rb",
|
36
|
+
"test/test_severity.rb"
|
41
37
|
]
|
42
38
|
s.homepage = %q{http://github.com/Graylog2/gelf-rb}
|
43
|
-
s.
|
44
|
-
s.
|
45
|
-
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.require_paths = [%q{lib}]
|
40
|
+
s.rubygems_version = %q{1.8.3}
|
46
41
|
s.summary = %q{Library to send GELF messages to Graylog2 logging server.}
|
47
|
-
s.test_files = [
|
48
|
-
"test/helper.rb",
|
49
|
-
"test/test_logger.rb",
|
50
|
-
"test/test_notifier.rb",
|
51
|
-
"test/test_severity.rb",
|
52
|
-
"test/test_ruby_sender.rb",
|
53
|
-
"test/test_deprecations.rb"
|
54
|
-
]
|
55
42
|
|
56
43
|
if s.respond_to? :specification_version then
|
57
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
58
44
|
s.specification_version = 3
|
59
45
|
|
60
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/lib/gelf.rb
CHANGED
data/lib/gelf/logger.rb
CHANGED
@@ -5,22 +5,22 @@ module GELF
|
|
5
5
|
def close
|
6
6
|
end
|
7
7
|
|
8
|
-
# Use it like Logger#add
|
8
|
+
# Use it like Logger#add... or better not to use at all.
|
9
9
|
def add(level, *args)
|
10
10
|
raise ArgumentError.new('Wrong arguments.') unless (0..2).include?(args.count)
|
11
11
|
|
12
12
|
# Ruby Logger's author is a maniac.
|
13
|
-
message,
|
13
|
+
message, progname = if args.count == 2
|
14
14
|
[args[0], args[1]]
|
15
15
|
elsif args.count == 0
|
16
|
-
[yield,
|
16
|
+
[yield, default_options['facility']]
|
17
17
|
elsif block_given?
|
18
18
|
[yield, args[0]]
|
19
19
|
else
|
20
|
-
[args[0],
|
20
|
+
[args[0], default_options['facility']]
|
21
21
|
end
|
22
22
|
|
23
|
-
hash = {'short_message' => message, 'facility' =>
|
23
|
+
hash = {'short_message' => message, 'facility' => progname}
|
24
24
|
hash.merge!(self.class.extract_hash_from_exception(message)) if message.is_a?(Exception)
|
25
25
|
notify_with_level(level, hash)
|
26
26
|
end
|
@@ -40,11 +40,14 @@ module GELF
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def <<(message)
|
43
|
-
|
43
|
+
notify_with_level(GELF::UNKNOWN, 'short_message' => message)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
# Graylog2 notifier, compatible with Ruby Logger.
|
48
|
+
# You can use it with Rails like this:
|
49
|
+
# config.logger = GELF::Logger.new("localhost", 12201, "WAN", { :facility => "appname" })
|
50
|
+
# config.colorize_logging = false
|
48
51
|
class Logger < Notifier
|
49
52
|
include LoggerCompatibility
|
50
53
|
@last_chunk_id = 0
|
data/lib/gelf/notifier.rb
CHANGED
@@ -6,18 +6,18 @@ module GELF
|
|
6
6
|
attr_accessor :last_chunk_id
|
7
7
|
end
|
8
8
|
|
9
|
-
attr_accessor :
|
10
|
-
attr_reader :max_chunk_size, :level
|
9
|
+
attr_accessor :enabled, :collect_file_and_line
|
10
|
+
attr_reader :max_chunk_size, :level, :default_options, :level_mapping
|
11
11
|
|
12
12
|
# +host+ and +port+ are host/ip and port of graylog2-server.
|
13
13
|
# +max_size+ is passed to max_chunk_size=.
|
14
14
|
# +default_options+ is used in notify!
|
15
15
|
def initialize(host = 'localhost', port = 12201, max_size = 'WAN', default_options = {})
|
16
16
|
@enabled = true
|
17
|
+
@collect_file_and_line = true
|
17
18
|
|
18
19
|
self.level = GELF::DEBUG
|
19
|
-
|
20
|
-
self.host, self.port, self.max_chunk_size = host, port, max_size
|
20
|
+
self.max_chunk_size = max_size
|
21
21
|
|
22
22
|
self.default_options = default_options
|
23
23
|
self.default_options['version'] = SPEC_VERSION
|
@@ -25,19 +25,42 @@ module GELF
|
|
25
25
|
self.default_options['level'] ||= GELF::UNKNOWN
|
26
26
|
self.default_options['facility'] ||= 'gelf-rb'
|
27
27
|
|
28
|
-
@sender = RubyUdpSender.new(host, port)
|
28
|
+
@sender = RubyUdpSender.new([[host, port]])
|
29
|
+
self.level_mapping = :logger
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get a list of receivers.
|
33
|
+
# notifier.addresses # => [['localhost', 12201], ['localhost', 12202]]
|
34
|
+
def addresses
|
35
|
+
@sender.addresses
|
36
|
+
end
|
37
|
+
|
38
|
+
# Set a list of receivers.
|
39
|
+
# notifier.addresses = [['localhost', 12201], ['localhost', 12202]]
|
40
|
+
def addresses=(addrs)
|
41
|
+
@sender.addresses = addrs
|
42
|
+
end
|
43
|
+
|
44
|
+
def host
|
45
|
+
warn "GELF::Notifier#host is deprecated. Use #addresses instead."
|
46
|
+
self.addresses.first[0]
|
47
|
+
end
|
48
|
+
|
49
|
+
def port
|
50
|
+
warn "GELF::Notifier#port is deprecated. Use #addresses instead."
|
51
|
+
self.addresses.first[1]
|
29
52
|
end
|
30
53
|
|
31
54
|
# +size+ may be a number of bytes, 'WAN' (1420 bytes) or 'LAN' (8154).
|
32
55
|
# Default (safe) value is 'WAN'.
|
33
56
|
def max_chunk_size=(size)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
57
|
+
case size.to_s.downcase
|
58
|
+
when 'wan'
|
59
|
+
@max_chunk_size = 1420
|
60
|
+
when 'lan'
|
61
|
+
@max_chunk_size = 8154
|
62
|
+
else
|
63
|
+
@max_chunk_size = size.to_int
|
41
64
|
end
|
42
65
|
end
|
43
66
|
|
@@ -49,6 +72,23 @@ module GELF
|
|
49
72
|
end
|
50
73
|
end
|
51
74
|
|
75
|
+
def default_options=(options)
|
76
|
+
@default_options = self.class.stringify_keys(options)
|
77
|
+
end
|
78
|
+
|
79
|
+
# +mapping+ may be a hash, 'logger' (GELF::LOGGER_MAPPING) or 'direct' (GELF::DIRECT_MAPPING).
|
80
|
+
# Default (compatible) value is 'logger'.
|
81
|
+
def level_mapping=(mapping)
|
82
|
+
case mapping.to_s.downcase
|
83
|
+
when 'logger'
|
84
|
+
@level_mapping = GELF::LOGGER_MAPPING
|
85
|
+
when 'direct'
|
86
|
+
@level_mapping = GELF::DIRECT_MAPPING
|
87
|
+
else
|
88
|
+
@level_mapping = mapping
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
52
92
|
def disable
|
53
93
|
@enabled = false
|
54
94
|
end
|
@@ -72,6 +112,7 @@ module GELF
|
|
72
112
|
# - string-like object (anything which responds to +to_s+) with optional hash-like object:
|
73
113
|
# notify!('Plain olde text message', :scribe => 'AlekSi')
|
74
114
|
# Resulted fields are merged with +default_options+, the latter will never overwrite the former.
|
115
|
+
# This method will raise +ArgumentError+ if arguments are wrong. Consider using notify instead.
|
75
116
|
def notify!(*args)
|
76
117
|
notify_with_level!(nil, *args)
|
77
118
|
end
|
@@ -111,10 +152,9 @@ module GELF
|
|
111
152
|
{ 'short_message' => object.to_s }
|
112
153
|
end
|
113
154
|
|
114
|
-
@hash = default_options.merge(args.merge(primary_data))
|
115
|
-
stringify_hash_keys
|
155
|
+
@hash = default_options.merge(self.class.stringify_keys(args.merge(primary_data)))
|
116
156
|
convert_hoptoad_keys_to_graylog2
|
117
|
-
set_file_and_line
|
157
|
+
set_file_and_line if @collect_file_and_line
|
118
158
|
set_timestamp
|
119
159
|
check_presence_of_mandatory_attributes
|
120
160
|
@hash
|
@@ -143,8 +183,8 @@ module GELF
|
|
143
183
|
frame = stack.shift
|
144
184
|
end while frame.include?(LIB_GELF_PATTERN)
|
145
185
|
match = CALLER_REGEXP.match(frame)
|
146
|
-
@hash['file'] = match[1]
|
147
|
-
@hash['line'] = match[2].to_i
|
186
|
+
@hash['file'] = match[1]
|
187
|
+
@hash['line'] = match[2].to_i
|
148
188
|
end
|
149
189
|
|
150
190
|
def set_timestamp
|
@@ -182,16 +222,18 @@ module GELF
|
|
182
222
|
def serialize_hash
|
183
223
|
raise ArgumentError.new("Hash is empty.") if @hash.nil? || @hash.empty?
|
184
224
|
|
185
|
-
@hash['level'] =
|
225
|
+
@hash['level'] = @level_mapping[@hash['level']]
|
186
226
|
|
187
227
|
Zlib::Deflate.deflate(@hash.to_json).bytes
|
188
228
|
end
|
189
229
|
|
190
|
-
def
|
191
|
-
|
192
|
-
value, key_s =
|
193
|
-
|
230
|
+
def self.stringify_keys(hash)
|
231
|
+
hash.keys.each do |key|
|
232
|
+
value, key_s = hash.delete(key), key.to_s
|
233
|
+
raise ArgumentError.new("Both #{key.inspect} and #{key_s} are present.") if hash.has_key?(key_s)
|
234
|
+
hash[key_s] = value
|
194
235
|
end
|
236
|
+
hash
|
195
237
|
end
|
196
238
|
end
|
197
239
|
end
|
data/lib/gelf/ruby_sender.rb
CHANGED
@@ -1,29 +1,20 @@
|
|
1
1
|
module GELF
|
2
2
|
# Plain Ruby UDP sender.
|
3
3
|
class RubyUdpSender
|
4
|
-
|
5
|
-
|
4
|
+
attr_accessor :addresses
|
5
|
+
|
6
|
+
def initialize(addresses)
|
7
|
+
@addresses = addresses
|
8
|
+
@i = 0
|
6
9
|
@socket = UDPSocket.open
|
7
10
|
end
|
8
11
|
|
9
12
|
def send_datagrams(datagrams)
|
13
|
+
host, port = @addresses[@i]
|
14
|
+
@i = (@i + 1) % @addresses.length
|
10
15
|
datagrams.each do |datagram|
|
11
|
-
@socket.send(datagram, 0,
|
16
|
+
@socket.send(datagram, 0, host, port)
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
15
|
-
|
16
|
-
# Plain Ruby TCP sender.
|
17
|
-
# class RubyTcpSender
|
18
|
-
# def initialize(host, port)
|
19
|
-
# @host, @port = host, port
|
20
|
-
# @socket = TCPSocket.open
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# def send_datagrams(datagrams)
|
24
|
-
# datagrams.each do |datagram|
|
25
|
-
# @socket.send(datagram, 0, @host, @port)
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
# end
|
29
20
|
end
|
data/lib/gelf/severity.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module GELF
|
2
|
-
# There are two things you should know about log
|
2
|
+
# There are two things you should know about log levels/severity:
|
3
3
|
# - syslog defines levels from 0 (Emergency) to 7 (Debug).
|
4
4
|
# 0 (Emergency) and 1 (Alert) levels are reserved for OS kernel.
|
5
5
|
# - Ruby default Logger defines levels from 0 (DEBUG) to 4 (FATAL) and 5 (UNKNOWN).
|
6
6
|
# Note that order is inverted.
|
7
7
|
# For compatibility we define our constants as Ruby Logger, and convert values before
|
8
|
-
# generating GELF message.
|
8
|
+
# generating GELF message, using defined mapping.
|
9
9
|
|
10
10
|
module Levels
|
11
11
|
DEBUG = 0
|
@@ -18,11 +18,20 @@ module GELF
|
|
18
18
|
|
19
19
|
include Levels
|
20
20
|
|
21
|
-
# Maps Ruby Logger levels to syslog levels as SyslogLogger and syslogger gems.
|
22
|
-
|
21
|
+
# Maps Ruby Logger levels to syslog levels as SyslogLogger and syslogger gems. This one is default.
|
22
|
+
LOGGER_MAPPING = {DEBUG => 7, # Debug
|
23
23
|
INFO => 6, # Info
|
24
24
|
WARN => 5, # Notice
|
25
25
|
ERROR => 4, # Warning
|
26
26
|
FATAL => 3, # Error
|
27
27
|
UNKNOWN => 1} # Alert – shouldn't be used
|
28
|
+
|
29
|
+
# Maps Ruby Logger levels to syslog levels as is.
|
30
|
+
DIRECT_MAPPING = {DEBUG => 7, # Debug
|
31
|
+
INFO => 6, # Info
|
32
|
+
# skip 5 Notice
|
33
|
+
WARN => 4, # Warning
|
34
|
+
ERROR => 3, # Error
|
35
|
+
FATAL => 2, # Critical
|
36
|
+
UNKNOWN => 1} # Alert – shouldn't be used
|
28
37
|
end
|
data/test/helper.rb
CHANGED
data/test/test_logger.rb
CHANGED
@@ -1,135 +1,139 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestLogger < Test::Unit::TestCase
|
4
|
-
context "with
|
4
|
+
context "with logger with mocked sender" do
|
5
5
|
setup do
|
6
6
|
Socket.stubs(:gethostname).returns('stubbed_hostname')
|
7
|
-
@
|
7
|
+
@logger = GELF::Logger.new
|
8
8
|
@sender = mock
|
9
|
-
@
|
9
|
+
@logger.instance_variable_set('@sender', @sender)
|
10
10
|
end
|
11
11
|
|
12
12
|
should "respond to #close" do
|
13
|
-
assert @
|
13
|
+
assert @logger.respond_to?(:close)
|
14
14
|
end
|
15
15
|
|
16
16
|
context "#add" do
|
17
17
|
# logger.add(Logger::INFO, 'Message')
|
18
|
-
should "implement add method with level and message from parameters" do
|
19
|
-
@
|
18
|
+
should "implement add method with level and message from parameters, facility from defaults" do
|
19
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
20
20
|
level == GELF::INFO &&
|
21
|
-
hash['short_message'] == 'Message'
|
21
|
+
hash['short_message'] == 'Message' &&
|
22
|
+
hash['facility'] == 'gelf-rb'
|
22
23
|
end
|
23
|
-
@
|
24
|
+
@logger.add(GELF::INFO, 'Message')
|
24
25
|
end
|
25
26
|
|
26
27
|
# logger.add(Logger::INFO, RuntimeError.new('Boom!'))
|
27
|
-
should "implement add method with level and exception from parameters" do
|
28
|
-
@
|
28
|
+
should "implement add method with level and exception from parameters, facility from defaults" do
|
29
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
29
30
|
level == GELF::INFO &&
|
30
31
|
hash['short_message'] == 'RuntimeError: Boom!' &&
|
31
|
-
hash['full_message'] =~ /^Backtrace/
|
32
|
+
hash['full_message'] =~ /^Backtrace/ &&
|
33
|
+
hash['facility'] == 'gelf-rb'
|
32
34
|
end
|
33
|
-
@
|
35
|
+
@logger.add(GELF::INFO, RuntimeError.new('Boom!'))
|
34
36
|
end
|
35
37
|
|
36
38
|
# logger.add(Logger::INFO) { 'Message' }
|
37
|
-
should "implement add method with level from parameter
|
38
|
-
@
|
39
|
+
should "implement add method with level from parameter, message from block, facility from defaults" do
|
40
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
39
41
|
level == GELF::INFO &&
|
40
|
-
hash['short_message'] == 'Message'
|
42
|
+
hash['short_message'] == 'Message' &&
|
43
|
+
hash['facility'] == 'gelf-rb'
|
41
44
|
end
|
42
|
-
@
|
45
|
+
@logger.add(GELF::INFO) { 'Message' }
|
43
46
|
end
|
44
47
|
|
45
48
|
# logger.add(Logger::INFO) { RuntimeError.new('Boom!') }
|
46
|
-
should "implement add method with level from parameter
|
47
|
-
@
|
49
|
+
should "implement add method with level from parameter, exception from block, facility from defaults" do
|
50
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
48
51
|
level == GELF::INFO &&
|
49
52
|
hash['short_message'] == 'RuntimeError: Boom!' &&
|
50
|
-
hash['full_message'] =~ /^Backtrace/
|
53
|
+
hash['full_message'] =~ /^Backtrace/ &&
|
54
|
+
hash['facility'] == 'gelf-rb'
|
51
55
|
end
|
52
|
-
@
|
56
|
+
@logger.add(GELF::INFO) { RuntimeError.new('Boom!') }
|
53
57
|
end
|
54
58
|
|
55
59
|
# logger.add(Logger::INFO, 'Message', 'Facility')
|
56
60
|
should "implement add method with level, message and facility from parameters" do
|
57
|
-
@
|
61
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
58
62
|
level == GELF::INFO &&
|
59
63
|
hash['short_message'] == 'Message' &&
|
60
64
|
hash['facility'] == 'Facility'
|
61
65
|
end
|
62
|
-
@
|
66
|
+
@logger.add(GELF::INFO, 'Message', 'Facility')
|
63
67
|
end
|
64
68
|
|
65
69
|
# logger.add(Logger::INFO, RuntimeError.new('Boom!'), 'Facility')
|
66
70
|
should "implement add method with level, exception and facility from parameters" do
|
67
|
-
@
|
71
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
68
72
|
level == GELF::INFO &&
|
69
73
|
hash['short_message'] == 'RuntimeError: Boom!' &&
|
70
74
|
hash['full_message'] =~ /^Backtrace/ &&
|
71
75
|
hash['facility'] == 'Facility'
|
72
76
|
end
|
73
|
-
@
|
77
|
+
@logger.add(GELF::INFO, RuntimeError.new('Boom!'), 'Facility')
|
74
78
|
end
|
75
79
|
|
76
80
|
# logger.add(Logger::INFO, 'Facility') { 'Message' }
|
77
|
-
should "implement add method with level and facility from parameters
|
78
|
-
@
|
81
|
+
should "implement add method with level and facility from parameters, message from block" do
|
82
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
79
83
|
level == GELF::INFO &&
|
80
84
|
hash['short_message'] == 'Message' &&
|
81
85
|
hash['facility'] == 'Facility'
|
82
86
|
end
|
83
|
-
@
|
87
|
+
@logger.add(GELF::INFO, 'Facility') { 'Message' }
|
84
88
|
end
|
85
89
|
|
86
90
|
# logger.add(Logger::INFO, 'Facility') { RuntimeError.new('Boom!') }
|
87
|
-
should "implement add method with level and facility from parameters
|
88
|
-
@
|
91
|
+
should "implement add method with level and facility from parameters, exception from block" do
|
92
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
89
93
|
level == GELF::INFO &&
|
90
94
|
hash['short_message'] == 'RuntimeError: Boom!' &&
|
91
95
|
hash['full_message'] =~ /^Backtrace/ &&
|
92
96
|
hash['facility'] == 'Facility'
|
93
97
|
end
|
94
|
-
@
|
98
|
+
@logger.add(GELF::INFO, 'Facility') { RuntimeError.new('Boom!') }
|
95
99
|
end
|
96
100
|
end
|
97
101
|
|
98
102
|
GELF::Levels.constants.each do |const|
|
99
103
|
# logger.error "Argument #{ @foo } mismatch."
|
100
|
-
should "call
|
101
|
-
@
|
102
|
-
@
|
104
|
+
should "call add with level #{const} from method name, message from parameter" do
|
105
|
+
@logger.expects(:add).with(GELF.const_get(const), 'message')
|
106
|
+
@logger.__send__(const.downcase, 'message')
|
103
107
|
end
|
104
108
|
|
105
109
|
# logger.fatal { "Argument 'foo' not given." }
|
106
|
-
should "call
|
107
|
-
@
|
108
|
-
@
|
110
|
+
should "call add with level #{const} from method name, message from block" do
|
111
|
+
@logger.expects(:add).with(GELF.const_get(const), 'message')
|
112
|
+
@logger.__send__(const.downcase) { 'message' }
|
109
113
|
end
|
110
114
|
|
111
115
|
# logger.info('initialize') { "Initializing..." }
|
112
|
-
should "call
|
113
|
-
@
|
114
|
-
@
|
116
|
+
should "call add with level #{const} from method name, facility from parameter, message from block" do
|
117
|
+
@logger.expects(:add).with(GELF.const_get(const), 'message', 'facility')
|
118
|
+
@logger.__send__(const.downcase, 'facility') { 'message' }
|
115
119
|
end
|
116
120
|
|
117
121
|
should "respond to #{const.downcase}?" do
|
118
|
-
@
|
119
|
-
assert @
|
120
|
-
@
|
121
|
-
assert @
|
122
|
-
@
|
123
|
-
assert !@
|
122
|
+
@logger.level = GELF.const_get(const) - 1
|
123
|
+
assert @logger.__send__(const.to_s.downcase + '?')
|
124
|
+
@logger.level = GELF.const_get(const)
|
125
|
+
assert @logger.__send__(const.to_s.downcase + '?')
|
126
|
+
@logger.level = GELF.const_get(const) + 1
|
127
|
+
assert !@logger.__send__(const.to_s.downcase + '?')
|
124
128
|
end
|
125
129
|
end
|
126
130
|
|
127
|
-
should "support
|
128
|
-
@
|
129
|
-
|
130
|
-
hash['
|
131
|
+
should "support Logger#<<" do
|
132
|
+
@logger.expects(:notify_with_level!).with do |level, hash|
|
133
|
+
level == GELF::UNKNOWN &&
|
134
|
+
hash['short_message'] == "Message"
|
131
135
|
end
|
132
|
-
@
|
136
|
+
@logger << "Message"
|
133
137
|
end
|
134
138
|
end
|
135
139
|
end
|
data/test/test_notifier.rb
CHANGED
@@ -6,12 +6,13 @@ class TestNotifier < Test::Unit::TestCase
|
|
6
6
|
should "allow access to host, port, max_chunk_size and default_options" do
|
7
7
|
Socket.expects(:gethostname).returns('default_hostname')
|
8
8
|
n = GELF::Notifier.new
|
9
|
-
assert_equal ['localhost', 12201, 1420], [n.
|
9
|
+
assert_equal [[['localhost', 12201]], 1420], [n.addresses, n.max_chunk_size]
|
10
10
|
assert_equal( { 'version' => '1.0', 'level' => GELF::UNKNOWN,
|
11
11
|
'host' => 'default_hostname', 'facility' => 'gelf-rb' },
|
12
12
|
n.default_options )
|
13
|
-
n.
|
14
|
-
assert_equal ['graylog2.org', 7777
|
13
|
+
n.addresses, n.max_chunk_size, n.default_options = [['graylog2.org', 7777]], :lan, {:host => 'grayhost'}
|
14
|
+
assert_equal [['graylog2.org', 7777]], n.addresses
|
15
|
+
assert_equal 8154, n.max_chunk_size
|
15
16
|
assert_equal({'host' => 'grayhost'}, n.default_options)
|
16
17
|
|
17
18
|
n.max_chunk_size = 1337.1
|
@@ -87,6 +88,10 @@ class TestNotifier < Test::Unit::TestCase
|
|
87
88
|
assert !hash.has_key?(:short_message)
|
88
89
|
end
|
89
90
|
|
91
|
+
should "not overwrite keys on convert" do
|
92
|
+
assert_raise(ArgumentError) { @notifier.__send__(:extract_hash, :short_message => :message1, 'short_message' => 'message2') }
|
93
|
+
end
|
94
|
+
|
90
95
|
should "use default_options" do
|
91
96
|
@notifier.default_options = {:foo => 'bar', 'short_message' => 'will be hidden by explicit argument', 'host' => 'some_host'}
|
92
97
|
hash = @notifier.__send__(:extract_hash, { 'version' => '1.0', 'short_message' => 'message' })
|
@@ -117,16 +122,18 @@ class TestNotifier < Test::Unit::TestCase
|
|
117
122
|
|
118
123
|
context "serialize_hash" do
|
119
124
|
setup do
|
125
|
+
@notifier.level_mapping = :direct
|
120
126
|
@notifier.instance_variable_set('@hash', { 'level' => GELF::WARN, 'field' => 'value' })
|
121
127
|
@data = @notifier.__send__(:serialize_hash)
|
122
|
-
|
128
|
+
assert @data.respond_to?(:each)
|
123
129
|
@deserialized_hash = JSON.parse(Zlib::Inflate.inflate(@data.to_a.pack('C*')))
|
124
130
|
assert_instance_of Hash, @deserialized_hash
|
125
131
|
end
|
126
132
|
|
127
|
-
should "map level" do
|
133
|
+
should "map level using mapping" do
|
128
134
|
assert_not_equal GELF::WARN, @deserialized_hash['level']
|
129
|
-
|
135
|
+
assert_not_equal GELF::LOGGER_MAPPING[GELF::WARN], @deserialized_hash['level']
|
136
|
+
assert_equal GELF::DIRECT_MAPPING[GELF::WARN], @deserialized_hash['level']
|
130
137
|
end
|
131
138
|
end
|
132
139
|
|
data/test/test_ruby_sender.rb
CHANGED
@@ -3,18 +3,25 @@ require 'helper'
|
|
3
3
|
class TestRubyUdpSender < Test::Unit::TestCase
|
4
4
|
context "with ruby sender" do
|
5
5
|
setup do
|
6
|
-
@
|
7
|
-
@sender = GELF::RubyUdpSender.new(
|
8
|
-
@
|
6
|
+
@addresses = [['localhost', 12201], ['localhost', 12202]]
|
7
|
+
@sender = GELF::RubyUdpSender.new(@addresses)
|
8
|
+
@datagrams1 = %w(d1 d2 d3)
|
9
|
+
@datagrams2 = %w(e1 e2 e3)
|
9
10
|
end
|
10
11
|
|
11
12
|
context "send_datagrams" do
|
12
13
|
setup do
|
13
|
-
@sender.send_datagrams(@
|
14
|
+
@sender.send_datagrams(@datagrams1)
|
15
|
+
@sender.send_datagrams(@datagrams2)
|
14
16
|
end
|
15
17
|
|
16
|
-
before_should "be called
|
17
|
-
UDPSocket.any_instance.expects(:send).times(3).with
|
18
|
+
before_should "be called 3 times with 1st and 2nd address" do
|
19
|
+
UDPSocket.any_instance.expects(:send).times(3).with do |datagram, _, host, port|
|
20
|
+
datagram.start_with?('d') && host == 'localhost' && port == 12201
|
21
|
+
end
|
22
|
+
UDPSocket.any_instance.expects(:send).times(3).with do |datagram, _, host, port|
|
23
|
+
datagram.start_with?('e') && host == 'localhost' && port == 12202
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
data/test/test_severity.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestSeverity < Test::Unit::TestCase
|
4
|
-
should "map Ruby Logger levels to syslog levels" do
|
5
|
-
GELF::
|
4
|
+
should "map Ruby Logger levels to syslog levels as SyslogLogger" do
|
5
|
+
GELF::LOGGER_MAPPING.each do |ruby_level, syslog_level|
|
6
6
|
assert_not_equal syslog_level, ruby_level
|
7
7
|
end
|
8
8
|
end
|
metadata
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gelf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 62196385
|
5
|
+
prerelease: 6
|
5
6
|
segments:
|
6
7
|
- 1
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
- beta
|
7
11
|
- 1
|
8
|
-
|
9
|
-
version: 1.1.3
|
12
|
+
version: 1.2.0.beta1
|
10
13
|
platform: ruby
|
11
14
|
authors:
|
12
|
-
-
|
15
|
+
- Alexey Palazhchenko
|
13
16
|
- Lennart Koopmann
|
14
17
|
autorequire:
|
15
18
|
bindir: bin
|
16
19
|
cert_chain: []
|
17
20
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
21
|
+
date: 2011-05-23 00:00:00 Z
|
20
22
|
dependencies:
|
21
23
|
- !ruby/object:Gem::Dependency
|
22
24
|
name: json
|
@@ -26,6 +28,7 @@ dependencies:
|
|
26
28
|
requirements:
|
27
29
|
- - ">="
|
28
30
|
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
29
32
|
segments:
|
30
33
|
- 0
|
31
34
|
version: "0"
|
@@ -39,6 +42,7 @@ dependencies:
|
|
39
42
|
requirements:
|
40
43
|
- - ">="
|
41
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
42
46
|
segments:
|
43
47
|
- 0
|
44
48
|
version: "0"
|
@@ -52,13 +56,14 @@ dependencies:
|
|
52
56
|
requirements:
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
55
60
|
segments:
|
56
61
|
- 0
|
57
62
|
version: "0"
|
58
63
|
type: :development
|
59
64
|
version_requirements: *id003
|
60
65
|
description: Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions.
|
61
|
-
email:
|
66
|
+
email: alexey.palazhchenko@gmail.com
|
62
67
|
executables: []
|
63
68
|
|
64
69
|
extensions: []
|
@@ -67,7 +72,6 @@ extra_rdoc_files:
|
|
67
72
|
- LICENSE
|
68
73
|
- README.rdoc
|
69
74
|
files:
|
70
|
-
- .gitignore
|
71
75
|
- CHANGELOG
|
72
76
|
- LICENSE
|
73
77
|
- README.rdoc
|
@@ -76,25 +80,21 @@ files:
|
|
76
80
|
- benchmarks/notifier.rb
|
77
81
|
- gelf.gemspec
|
78
82
|
- lib/gelf.rb
|
79
|
-
- lib/gelf/deprecations.rb
|
80
|
-
- lib/gelf/em_sender.rb
|
81
83
|
- lib/gelf/logger.rb
|
82
84
|
- lib/gelf/notifier.rb
|
83
85
|
- lib/gelf/ruby_sender.rb
|
84
86
|
- lib/gelf/severity.rb
|
85
87
|
- test/helper.rb
|
86
|
-
- test/test_deprecations.rb
|
87
88
|
- test/test_logger.rb
|
88
89
|
- test/test_notifier.rb
|
89
90
|
- test/test_ruby_sender.rb
|
90
91
|
- test/test_severity.rb
|
91
|
-
has_rdoc: true
|
92
92
|
homepage: http://github.com/Graylog2/gelf-rb
|
93
93
|
licenses: []
|
94
94
|
|
95
95
|
post_install_message:
|
96
|
-
rdoc_options:
|
97
|
-
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
98
|
require_paths:
|
99
99
|
- lib
|
100
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -102,28 +102,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
105
106
|
segments:
|
106
107
|
- 0
|
107
108
|
version: "0"
|
108
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
110
|
none: false
|
110
111
|
requirements:
|
111
|
-
- - "
|
112
|
+
- - ">"
|
112
113
|
- !ruby/object:Gem::Version
|
114
|
+
hash: 25
|
113
115
|
segments:
|
114
|
-
-
|
115
|
-
|
116
|
+
- 1
|
117
|
+
- 3
|
118
|
+
- 1
|
119
|
+
version: 1.3.1
|
116
120
|
requirements: []
|
117
121
|
|
118
122
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.3
|
123
|
+
rubygems_version: 1.8.3
|
120
124
|
signing_key:
|
121
125
|
specification_version: 3
|
122
126
|
summary: Library to send GELF messages to Graylog2 logging server.
|
123
|
-
test_files:
|
124
|
-
|
125
|
-
- test/test_logger.rb
|
126
|
-
- test/test_notifier.rb
|
127
|
-
- test/test_severity.rb
|
128
|
-
- test/test_ruby_sender.rb
|
129
|
-
- test/test_deprecations.rb
|
127
|
+
test_files: []
|
128
|
+
|
data/lib/gelf/deprecations.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# Deprecated, do not use in new code, to be removed.
|
2
|
-
class Gelf
|
3
|
-
def deprecate(instead)
|
4
|
-
Kernel.caller.first =~ /:in `(.+)'$/
|
5
|
-
warn "Gelf##{$1} is deprecated. Use #{instead} instead."
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_reader :notifier, :message
|
9
|
-
|
10
|
-
def initialize(hostname, port)
|
11
|
-
deprecate('GELF::Notifier.new(hostname, port)')
|
12
|
-
@notifier = GELF::Notifier.new(hostname, port)
|
13
|
-
@message = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
# bizarre, but Gelf did this...
|
17
|
-
def send
|
18
|
-
deprecate('GELF::Notifier#notify(message)')
|
19
|
-
@notifier.notify(@message)
|
20
|
-
end
|
21
|
-
|
22
|
-
[:short_message, :full_message, :level, :host, :line, :file].each do |attribute|
|
23
|
-
define_method attribute do
|
24
|
-
deprecate("GELF::Message##{attribute}")
|
25
|
-
@message[attribute]
|
26
|
-
end
|
27
|
-
|
28
|
-
define_method "#{attribute}=" do |value|
|
29
|
-
deprecate("GELF::Message##{attribute} = value")
|
30
|
-
@message[attribute] = value
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def add_additional(key, value)
|
35
|
-
@message[key] = value
|
36
|
-
end
|
37
|
-
end
|
data/lib/gelf/em_sender.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# module GELF
|
2
|
-
# # TCP Sender for EventMachine.
|
3
|
-
# class EMTcpSender
|
4
|
-
# def initialize(host, port)
|
5
|
-
# end
|
6
|
-
#
|
7
|
-
# def send_datagrams(datagrams)
|
8
|
-
# end
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# # UDP Sender for EventMachine.
|
12
|
-
# class EMUdpSender
|
13
|
-
# def initialize(host, port)
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# def send_datagrams(datagrams)
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
# end
|
data/test/test_deprecations.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestDeprecations < Test::Unit::TestCase
|
4
|
-
context "with Gelf object" do
|
5
|
-
setup do
|
6
|
-
@verbose, $VERBOSE = $VERBOSE, nil
|
7
|
-
@g = Gelf.new('host', 12345)
|
8
|
-
end
|
9
|
-
|
10
|
-
teardown do
|
11
|
-
$VERBOSE = @verbose
|
12
|
-
end
|
13
|
-
|
14
|
-
should "deprecate Gelf.new" do
|
15
|
-
assert_equal Gelf, @g.class
|
16
|
-
assert_equal 'host', @g.notifier.host
|
17
|
-
assert_equal 12345, @g.notifier.port
|
18
|
-
assert_equal Hash, @g.message.class
|
19
|
-
end
|
20
|
-
|
21
|
-
should "deprecate Gelf#send" do
|
22
|
-
@g.notifier.expects(:notify).with(@g.message)
|
23
|
-
@g.send
|
24
|
-
end
|
25
|
-
|
26
|
-
[:short_message, :full_message, :level, :host, :line, :file].each do |a|
|
27
|
-
should "deprecate Gelf##{a} and Gelf##{a}=" do
|
28
|
-
@g.__send__("#{a}=", 'value')
|
29
|
-
assert_equal 'value', @g.__send__(a)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
should "set add additional params" do
|
34
|
-
@g.add_additional(:key, 'value')
|
35
|
-
assert_equal 'value', @g.message[:key]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|