log4r-gelf 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in log4r-gelf.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,68 @@
1
+ require 'gelf'
2
+ require 'log4r/outputter/outputter'
3
+
4
+ module Log4r
5
+ module Gelf
6
+
7
+ class GelfOutputter < Log4r::Outputter
8
+
9
+ LEVELS_MAP = {
10
+ "DEBUG" => GELF::Levels::DEBUG,
11
+ "INFO" => GELF::Levels::INFO,
12
+ "WARN" => GELF::Levels::ERROR,
13
+ "ERROR" => GELF::Levels::FATAL,
14
+ "FATAL" => GELF::Levels::FATAL,
15
+ }
16
+
17
+ def initialize(_name, hash={})
18
+ super(_name, hash)
19
+
20
+ server = hash[:gelf_server] || "127.0.0.1"
21
+ port = hash[:gelf_port] || 12201
22
+ max_chunk_size = hash[:max_chunk_size] || 'LAN'
23
+ opts = {}
24
+ opts['host'] = hash[:host] if hash[:host]
25
+ opts['facility'] = hash[:facility] if hash[:facility]
26
+ opts['level'] = hash[:level] if hash[:level]
27
+
28
+ @notifier = GELF::Notifier.new(server, port, max_chunk_size, opts)
29
+ end
30
+
31
+ private
32
+
33
+ def canonical_log(logevent)
34
+ level = LEVELS_MAP[Log4r::LNAMES[logevent.level]]
35
+
36
+ msg = "#{logevent.fullname}: #{logevent.data.to_s}"
37
+
38
+ if logevent.data.respond_to?(:backtrace)
39
+ trace = logevent.data.backtrace
40
+ if trace
41
+ full_msg = trace.join("\n")
42
+ file = trace[0].split(":")[0]
43
+ line = trace[0].split(":")[1]
44
+ end
45
+ end
46
+
47
+ if logevent.tracer
48
+ trace = logevent.tracer.join("\n")
49
+ full_msg = "#{full_msg}\nLog tracer:\n#{trace}"
50
+ file = logevent.tracer[0].split(":")[0]
51
+ line = logevent.tracer[0].split(":")[1]
52
+ end
53
+
54
+ @notifier.notify!(
55
+ :short_message => msg,
56
+ :full_message => full_msg,
57
+ :level => level,
58
+ :file => file,
59
+ :line => line
60
+ )
61
+ rescue => err
62
+ puts "Graylog2 logger. Could not send message: " + err.message
63
+ puts err.backtrace.join("\n") if err.backtrace
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Log4r
2
+ module Gelf
3
+ VERSION = "0.5.0"
4
+ end
5
+ end
data/lib/log4r-gelf.rb ADDED
@@ -0,0 +1 @@
1
+ require 'log4r-gelf/gelf_outputter'
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "log4r-gelf/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "log4r-gelf"
7
+ s.version = Log4r::Gelf::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matt Conway"]
10
+ s.email = ["matt@conwaysplace.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{A Log4r appender for logging to a gelf sink, e.g. the graylog2 server}
13
+ s.description = %q{A Log4r appender for logging to a gelf sink, e.g. the graylog2 server}
14
+
15
+ s.rubyforge_project = "log4r-gelf"
16
+
17
+ s.files = %w{
18
+ Gemfile
19
+ Rakefile
20
+ lib/log4r-gelf.rb
21
+ lib/log4r-gelf/gelf_outputter.rb
22
+ lib/log4r-gelf/version.rb
23
+ log4r-gelf.gemspec
24
+ }
25
+ s.test_files = []
26
+ s.executables = []
27
+ s.require_paths = ["lib"]
28
+
29
+ s.add_dependency("log4r", '~> 1.0')
30
+ s.add_dependency("gelf", '~> 1.1.3')
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log4r-gelf
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.5.0
6
+ platform: ruby
7
+ authors:
8
+ - Matt Conway
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-08 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: log4r
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "1.0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: gelf
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 1.1.3
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: A Log4r appender for logging to a gelf sink, e.g. the graylog2 server
39
+ email:
40
+ - matt@conwaysplace.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - Gemfile
49
+ - Rakefile
50
+ - lib/log4r-gelf.rb
51
+ - lib/log4r-gelf/gelf_outputter.rb
52
+ - lib/log4r-gelf/version.rb
53
+ - log4r-gelf.gemspec
54
+ has_rdoc: true
55
+ homepage: ""
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project: log4r-gelf
78
+ rubygems_version: 1.5.0
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: A Log4r appender for logging to a gelf sink, e.g. the graylog2 server
82
+ test_files: []
83
+