logging-graylog 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logging/appenders/graylog.rb +63 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09f470280eb03cfe64a940b5414ba322173a17ce
|
4
|
+
data.tar.gz: 373dcbfe294ed5147e3ded4a73d4d10eec7e545e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1635afdb1fec18d9d7cdac82800b02864c3b303bda6c1bf679a305a875e8b6280066e813871d89d95b8ba4b5d7e0135ef33bf99a6b9b501159745efd0fd4da8
|
7
|
+
data.tar.gz: a38da528cef5541851751ed08315c5a9cf987712109dda0dc7b2ded2e93d896f6fe74dfbc107d03c086570746f95aaac5fb1c7633b34d3c7f193c56c91f3b1db
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'gelf'
|
2
|
+
require 'logging'
|
3
|
+
|
4
|
+
module Logging
|
5
|
+
module Appenders
|
6
|
+
|
7
|
+
# Accessor / Factory for the Email appender.
|
8
|
+
def self.graylog(*args)
|
9
|
+
return ::Logging::Appenders::Graylog if args.empty?
|
10
|
+
::Logging::Appenders::Graylog.new(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
LEVELS_MAP = {
|
14
|
+
'DEBUG' => GELF::Levels::DEBUG,
|
15
|
+
'INFO' => GELF::Levels::INFO,
|
16
|
+
'WARN' => GELF::Levels::WARN,
|
17
|
+
'ERROR' => GELF::Levels::ERROR,
|
18
|
+
'FATAL' => GELF::Levels::FATAL
|
19
|
+
}
|
20
|
+
|
21
|
+
# Provides an appender that can send log messages to graylog
|
22
|
+
class Graylog < ::Logging::Appender
|
23
|
+
|
24
|
+
def initialize(name, opts = {})
|
25
|
+
super(name, opts)
|
26
|
+
@name = name
|
27
|
+
@server = opts.fetch(:server, '127.0.0.1')
|
28
|
+
@port = opts.fetch(:port, 12201)
|
29
|
+
@max_chunk_size = opts.fetch(:max_chunk_size, 'WAN')
|
30
|
+
hash = {}
|
31
|
+
hash['host'] = opts.fetch(:host, Socket.gethostname)
|
32
|
+
hash['facility'] = opts.fetch(:facility, 'gelf-rb')
|
33
|
+
hash['level'] = LEVELS_MAP[opts.fetch(:level, 'DEBUG')]
|
34
|
+
@gelf_notifier = GELF::Notifier.new(@server, @port, @max_chunk_size, hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def write(logevent)
|
40
|
+
opts = {}
|
41
|
+
opts[:logger] = @name
|
42
|
+
opts[:level] = logevent.level
|
43
|
+
opts[:timestamp] = logevent.time
|
44
|
+
if logevent.data.respond_to?(:backtrace)
|
45
|
+
trace = logevent.data.backtrace
|
46
|
+
opts['_exception'] = format(logevent.data.class)
|
47
|
+
opts[:short_message] = "Caught #{logevent.data.class}: #{logevent.data.message}"
|
48
|
+
opts[:full_message] = "Backtrace:\n" + trace.join("\n")
|
49
|
+
opts[:file] = trace[0].split(':')[0]
|
50
|
+
opts[:line] = trace[0].split(':')[1]
|
51
|
+
else
|
52
|
+
opts[:short_message] = format(logevent.data)
|
53
|
+
opts[:full_message] = @layout.format(logevent)
|
54
|
+
end
|
55
|
+
@gelf_notifier.notify!(opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def format(event)
|
59
|
+
event.inspect
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logging-graylog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tessy Joseph John
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/logging/appenders/graylog.rb
|
19
20
|
- lib/logging/plugins/graylog.rb
|
20
21
|
homepage: http://rubygems.org/gems/logging-graylog
|
21
22
|
licenses:
|
@@ -27,17 +28,17 @@ require_paths:
|
|
27
28
|
- lib
|
28
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
35
|
requirements:
|
35
|
-
- -
|
36
|
+
- - '>='
|
36
37
|
- !ruby/object:Gem::Version
|
37
38
|
version: '0'
|
38
39
|
requirements: []
|
39
40
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.6.
|
41
|
+
rubygems_version: 2.6.11
|
41
42
|
signing_key:
|
42
43
|
specification_version: 4
|
43
44
|
summary: logging-graylog!
|