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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 242f08888fcd51522a2ce5a9f5fa3757a5bc1ff8
4
- data.tar.gz: 955dfd154d3010f88e9757ed7545271221735814
3
+ metadata.gz: 09f470280eb03cfe64a940b5414ba322173a17ce
4
+ data.tar.gz: 373dcbfe294ed5147e3ded4a73d4d10eec7e545e
5
5
  SHA512:
6
- metadata.gz: 400682a85be4242ca709509cd240b7a6895812208e710abf4ce9b5ea3745b7471020611cd8bb4be1a921ec3cd170dd9c46c02c87face12aa92c9d7c946adde9b
7
- data.tar.gz: 80cfd170dbb7c8b018c37a06ae1dd731eb6ebefc534deb80e1b2198a5ae71635c53d5f5a95f0729ca83f05ff44e91bd1358e6f54e96fd7cfe7097045079393c1
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.0.0
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.12
41
+ rubygems_version: 2.6.11
41
42
  signing_key:
42
43
  specification_version: 4
43
44
  summary: logging-graylog!