log4r-logdna 0.3.0
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/.gitignore +5 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/log4r-logdna.rb +1 -0
- data/lib/log4r-logdna/logdna_outputter.rb +103 -0
- data/lib/log4r-logdna/version.rb +5 -0
- data/log4r-logdna.gemspec +30 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 84a0ba052d0d47e86acdd7acdbeced554ee18b2f
|
4
|
+
data.tar.gz: acd2d877b46bf786ad6b36e6e422be408e505008
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91fd882cddd984df9548a7d195c211d4055d7f8a8407a7b99d062f8b97511571cf76e1f232cea201252d59fea8c3b1e41379253ec144f0239111a65d1283231a
|
7
|
+
data.tar.gz: 60208838b08c28df7e43e5d60267311f38a711c9ab0cf5daebb450763dcad2321c9941c2e5a3ac60db1ab664175245854a66e08b71641c2b98b825f31bcc9afc
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Mike Machado
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Log4r::Logdna
|
2
|
+
|
3
|
+
Log4r appender that outputs to LogDNA service. Sends all the Log4r logging context data as LogDNA data
|
4
|
+
via the JSON API.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'log4r-logdna'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install log4r-logdna
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Add the LogdnaOutputter to your log4r configuration:
|
25
|
+
|
26
|
+
|
27
|
+
```yaml
|
28
|
+
outputters:
|
29
|
+
- type: LogdnaOutputter
|
30
|
+
name: logdna_output
|
31
|
+
```
|
32
|
+
|
33
|
+
The LogDNA API key can be set with the `logdna_key` outputter option, or simply by setting the `LOGDNA_KEY` environment
|
34
|
+
variable.
|
35
|
+
|
36
|
+
By default, the LogDNA `env` is detected using the `RACK_ENV` environment variable but can be changed via the Outputter
|
37
|
+
configuration options.
|
38
|
+
|
39
|
+
The LogDNA `app` field is set to the name of the Log4r logger.
|
40
|
+
|
41
|
+
Since LogDNA shows the app name and log level outside of the message, an optimization is to use the `PatternFormatter`
|
42
|
+
to drop the logger name and log level, such as:
|
43
|
+
|
44
|
+
```yaml
|
45
|
+
outputters:
|
46
|
+
- type: LogdnaOutputter
|
47
|
+
name: logdna_output
|
48
|
+
formatter :
|
49
|
+
pattern : '%m'
|
50
|
+
type : PatternFormatter
|
51
|
+
```
|
52
|
+
|
53
|
+
Supported optional Outputter options:
|
54
|
+
|
55
|
+
<pre>
|
56
|
+
logdna_key: LogDNA API key, if not using the LOGDNA_KEY environment variable
|
57
|
+
hostname: Override auto-detected hostname
|
58
|
+
ip: Send IP information to LogDNA
|
59
|
+
mac: Send MAC information to LogDNA
|
60
|
+
env: Override auto-detected RACK_ENV value
|
61
|
+
</pre>
|
62
|
+
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/LeadDyno/log4r-logdna.
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "log4r/logdna"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/log4r-logdna.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'log4r-logdna/logdna_outputter'
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'logdna/client'
|
2
|
+
require 'log4r/outputter/outputter'
|
3
|
+
|
4
|
+
module Log4r
|
5
|
+
|
6
|
+
class LogdnaOutputter < Log4r::Outputter
|
7
|
+
|
8
|
+
def initialize(_name, hash={})
|
9
|
+
super(_name, hash)
|
10
|
+
|
11
|
+
logdna_key = hash['logdna_key'] || ENV['LOGDNA_KEY']
|
12
|
+
opts = {}
|
13
|
+
opts[:hostname] = hash['hostname'] if hash['hostname']
|
14
|
+
opts[:ip] = hash['ip'] if hash['ip']
|
15
|
+
opts[:mac] = hash['mac'] if hash['mac']
|
16
|
+
opts[:env] = hash['env'] || ENV['RACK_ENV']
|
17
|
+
|
18
|
+
@gdc_key = hash.has_key?('global_context_key') ? hash['global_context_key'] : "gdc"
|
19
|
+
@ndc_prefix = hash.has_key?('nested_context_prefix') ? hash['nested_context_prefix'] : "ndc_"
|
20
|
+
@mdc_prefix = hash.has_key?('mapped_context_prefix') ? hash['mapped_context_prefix'] : "mdc_"
|
21
|
+
|
22
|
+
@client = ::Logdna::Client.new(logdna_key, opts)
|
23
|
+
end
|
24
|
+
|
25
|
+
def format_attribute(value)
|
26
|
+
value.inspect
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def canonical_log(logevent)
|
32
|
+
|
33
|
+
msg = {
|
34
|
+
:level => Log4r::LNAMES[logevent.level]
|
35
|
+
}
|
36
|
+
|
37
|
+
if logevent.data.respond_to?(:backtrace)
|
38
|
+
trace = logevent.data.backtrace
|
39
|
+
if trace
|
40
|
+
msg["_exception"] = format_attribute(logevent.data.class)
|
41
|
+
msg[:message] = "Caught #{logevent.data.class}: #{logevent.data.message}"
|
42
|
+
msg[:full_message] = "Backtrace:\n" + trace.join("\n")
|
43
|
+
msg[:file] = trace[0].split(":")[0]
|
44
|
+
msg[:line] = trace[0].split(":")[1]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if logevent.tracer
|
49
|
+
trace = logevent.tracer.join("\n")
|
50
|
+
msg[:full_message] = "#{msg[:full_message]}\nLog tracer:\n#{trace}"
|
51
|
+
msg[:file] = logevent.tracer[0].split(":")[0]
|
52
|
+
msg[:line] = logevent.tracer[0].split(":")[1]
|
53
|
+
end
|
54
|
+
|
55
|
+
gdc = Log4r::GDC.get
|
56
|
+
if gdc && gdc != $0 && @gdc_key
|
57
|
+
begin
|
58
|
+
msg["_#{@gdc_key}"] = format_attribute(gdc)
|
59
|
+
rescue
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if Log4r::NDC.get_depth > 0 && @ndc_prefix
|
64
|
+
Log4r::NDC.clone_stack.each_with_index do |x, i|
|
65
|
+
begin
|
66
|
+
msg["_#{@ndc_prefix}#{i}"] = format_attribute(x)
|
67
|
+
rescue
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
mdc = Log4r::MDC.get_context
|
73
|
+
if mdc && mdc.size > 0 && @mdc_prefix
|
74
|
+
mdc.each do |k, v|
|
75
|
+
begin
|
76
|
+
msg["_#{@mdc_prefix}#{k}"] = format_attribute(v)
|
77
|
+
rescue
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Extract any context values out of the logevent's data hash.
|
83
|
+
if logevent.data.respond_to?(:has_key?)
|
84
|
+
logevent.data.each do |key, value|
|
85
|
+
if key.to_s =~ /^_/
|
86
|
+
msg[key] = value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
msg[:message] = logevent.data[:message] if logevent.data.has_key?(:message)
|
91
|
+
end
|
92
|
+
|
93
|
+
msg[:message] = format(logevent) unless msg[:message]
|
94
|
+
|
95
|
+
@client.tobuffer(msg.to_json, {:app => logevent.fullname})
|
96
|
+
rescue => err
|
97
|
+
puts "LogDNA logger. Could not send message: " + err.message
|
98
|
+
puts err.backtrace.join("\n") if err.backtrace
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "log4r-logdna/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "log4r-logdna"
|
8
|
+
spec.version = Log4r::Logdna::VERSION
|
9
|
+
spec.authors = ["Mike Machado"]
|
10
|
+
spec.email = ["mike@leaddyno.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Log4r appender that outputs to LogDNA service.}
|
13
|
+
spec.description = %q{Log4r appender that outputs to LogDNA service.}
|
14
|
+
spec.homepage = "https://github.com/LeadDyno/log4r-logdna"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency("log4r", '~> 1.1.10')
|
25
|
+
spec.add_dependency("logdna", '>= 1.0.9')
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log4r-logdna
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Machado
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: log4r
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.10
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: logdna
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.9
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.9
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.15'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.15'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Log4r appender that outputs to LogDNA service.
|
84
|
+
email:
|
85
|
+
- mike@leaddyno.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/log4r-logdna.rb
|
100
|
+
- lib/log4r-logdna/logdna_outputter.rb
|
101
|
+
- lib/log4r-logdna/version.rb
|
102
|
+
- log4r-logdna.gemspec
|
103
|
+
homepage: https://github.com/LeadDyno/log4r-logdna
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.6.12
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Log4r appender that outputs to LogDNA service.
|
127
|
+
test_files: []
|