log4r_remote_syslog_outputter 0.0.1
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/.gitignore +4 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/README +4 -0
- data/Rakefile +18 -0
- data/lib/log4r_remote_syslog_outputter.rb +3 -0
- data/lib/log4r_remote_syslog_outputter/log4r/outputter/remote_syslog_outputter.rb +40 -0
- data/lib/log4r_remote_syslog_outputter/version.rb +3 -0
- data/log4r_remote_syslog_outputter.gemspec +25 -0
- data/spec/config_files/config.xml +15 -0
- data/spec/lib/log4r/logger_spec.rb +26 -0
- data/spec/lib/log4r/outputter/remote_syslog_outputter_spec.rb +101 -0
- data/spec/spec_helper.rb +8 -0
- metadata +111 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
desc 'Default: run specs.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run specs"
|
8
|
+
RSpec::Core::RakeTask.new do |t|
|
9
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
10
|
+
# Put spec opts in a file named .rspec in root
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Generate code coverage"
|
14
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
15
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
16
|
+
t.rcov = true
|
17
|
+
t.rcov_opts = ['--exclude', 'spec']
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'log4r/outputter/outputter'
|
2
|
+
require 'remote_syslog_logger/udp_sender'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Log4r
|
6
|
+
class RemoteSyslogOutputter < Log4r::Outputter
|
7
|
+
# The url is required here but it has to be specified
|
8
|
+
# as an option (not a parameter) because that's the only
|
9
|
+
# way it can be created from a configuration file.
|
10
|
+
# :url is given when an XML configuration file is used
|
11
|
+
# 'url' is given when a YAML configuration file is used
|
12
|
+
def initialize(name, options = {})
|
13
|
+
url = options['url']
|
14
|
+
url ||= options[:url]
|
15
|
+
uri = URI.parse(url)
|
16
|
+
options.dup.tap do |o|
|
17
|
+
super(name, [:level, :formatter, :url, 'url'].inject({}) { |h, i|
|
18
|
+
h.tap { |a|
|
19
|
+
a[i] = o.delete(i)
|
20
|
+
}
|
21
|
+
})
|
22
|
+
@udp_sender = RemoteSyslogLogger::UdpSender.new(uri.host, uri.port, symbolize_keys(o))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
private
|
26
|
+
|
27
|
+
def write(data)
|
28
|
+
@udp_sender.write(data)
|
29
|
+
end
|
30
|
+
|
31
|
+
def symbolize_keys(hash)
|
32
|
+
output = {}
|
33
|
+
hash.each do |key, value|
|
34
|
+
output[key.to_sym] = value
|
35
|
+
end
|
36
|
+
output
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "log4r_remote_syslog_outputter/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "log4r_remote_syslog_outputter"
|
7
|
+
s.version = Log4rRemoteSyslogOutputter::VERSION
|
8
|
+
s.authors = ["Rob Hanlon"]
|
9
|
+
s.email = ["rob@mediapiston.com"]
|
10
|
+
s.homepage = "http://www.mediapiston.com/"
|
11
|
+
s.summary = %q{A Log4r outputter that outputs via remote syslog}
|
12
|
+
s.description = %q{The outputter included in this library simply ties Log4r's Outputter interface together with remote_syslog_logger.}
|
13
|
+
|
14
|
+
s.add_dependency('log4r', '>= 1.1.9')
|
15
|
+
s.add_dependency('remote_syslog_logger', '>= 1.0.3')
|
16
|
+
|
17
|
+
s.add_development_dependency('rspec', '>= 2.7.0')
|
18
|
+
|
19
|
+
s.rubyforge_project = "log4r_remote_syslog_outputter"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<log4r_config>
|
2
|
+
|
3
|
+
<!-- Outputters -->
|
4
|
+
<outputter name="remote_syslog_outputter" type="RemoteSyslogOutputter" level="ALL" url="http://localhost:3203">
|
5
|
+
<formatter type="Log4r::PatternFormatter">
|
6
|
+
<pattern>=>[%5l %d] %C: %M [%t]</pattern>
|
7
|
+
</formatter>
|
8
|
+
</outputter>
|
9
|
+
|
10
|
+
<!-- Loggers -->
|
11
|
+
<logger name="my_awesome_logger" level="ALL" additive="false" trace="true">
|
12
|
+
<outputter>remote_syslog_outputter</outputter>
|
13
|
+
</logger>
|
14
|
+
|
15
|
+
</log4r_config>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Log4r::Logger do
|
4
|
+
describe 'with RemoteSyslogOutputter' do
|
5
|
+
let(:url) {'http://localhost:' + (rand(65535 - 1024)+1024).to_s }
|
6
|
+
let(:uri) { URI.parse(url) }
|
7
|
+
let(:host) { uri.host }
|
8
|
+
let(:port) { uri.port }
|
9
|
+
let(:outputter) { Log4r::RemoteSyslogOutputter.new('outputter', :url => url) }
|
10
|
+
|
11
|
+
let(:socket) { UDPSocket.new }
|
12
|
+
|
13
|
+
subject { Log4r::Logger.new('Logger') }
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
subject.outputters << outputter
|
17
|
+
socket.bind(host, port)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should make a UDP request to localhost' do
|
21
|
+
subject.info 'Info'
|
22
|
+
message, = socket.recvfrom(1024)
|
23
|
+
message.should =~ /Logger.*Info/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Log4r::RemoteSyslogOutputter do
|
4
|
+
|
5
|
+
let(:name) { 'name' }
|
6
|
+
let(:url) { 'http://localhost:65535' }
|
7
|
+
let(:uri) { URI.parse(url) }
|
8
|
+
let(:host) { uri.host }
|
9
|
+
let(:port) { uri.port }
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
|
13
|
+
subject { Log4r::RemoteSyslogOutputter }
|
14
|
+
|
15
|
+
it 'should create a new RemoteSyslogLogger::UdpSender' do
|
16
|
+
RemoteSyslogLogger::UdpSender
|
17
|
+
.should_receive(:new)
|
18
|
+
.with(host, port, {})
|
19
|
+
|
20
|
+
subject.new(name, :url => url)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not pass along :level and :formatter, and 'url' to RemoteSyslogLogger::UdpSender's constructor" do
|
24
|
+
RemoteSyslogLogger::UdpSender
|
25
|
+
.should_receive(:new)
|
26
|
+
.with(host, port, :key => 'value')
|
27
|
+
|
28
|
+
subject.new(name, :url => url, :level => nil, :formatter => nil, :key => 'value')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should symbolize the extra keys" do
|
32
|
+
RemoteSyslogLogger::UdpSender
|
33
|
+
.should_receive(:new)
|
34
|
+
.with(host, port, :program => 'value')
|
35
|
+
|
36
|
+
subject.new(name, :url => url, :level => nil, :formatter => nil, 'program' => 'value')
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should not modify the input options hash, using a duplicate' do
|
41
|
+
options = {:url => url, :level => nil, :formatter => nil}
|
42
|
+
orig_options = options.dup
|
43
|
+
|
44
|
+
RemoteSyslogLogger::UdpSender.should_receive(:new)
|
45
|
+
|
46
|
+
subject.new(name, options)
|
47
|
+
|
48
|
+
options.should == orig_options
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#write' do
|
53
|
+
let(:udp_sender) { stub }
|
54
|
+
let(:data) { stub }
|
55
|
+
|
56
|
+
subject { Log4r::RemoteSyslogOutputter.new(name, :url => url) }
|
57
|
+
|
58
|
+
it 'should delegate to udp_sender#write' do
|
59
|
+
RemoteSyslogLogger::UdpSender.stub!(:new).and_return(udp_sender)
|
60
|
+
|
61
|
+
udp_sender.should_receive(:write).with(data)
|
62
|
+
|
63
|
+
subject.send(:write, data)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when creating via a configuration file' do
|
68
|
+
|
69
|
+
let(:logger_name) { "my_awesome_logger" }
|
70
|
+
let(:outputter_name) { "remote_syslog_outputter" }
|
71
|
+
let(:hash_from_yaml) do
|
72
|
+
{
|
73
|
+
"loggers"=> [
|
74
|
+
{"name"=> logger_name, "level"=>"ALL", "trace" => true, "additive"=>false, "outputters"=>[outputter_name]}
|
75
|
+
],
|
76
|
+
"outputters" => [
|
77
|
+
{"type" => "RemoteSyslogOutputter", "name" => outputter_name, "level" => "ALL",
|
78
|
+
"url" => "http://localhost:3203", "program" =>"Test",
|
79
|
+
"formatter" => {"pattern"=>"%C %l: %m", "type"=>"PatternFormatter" }
|
80
|
+
}
|
81
|
+
]
|
82
|
+
}
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should work create an outputter from a YAML config file' do
|
87
|
+
Log4r::YamlConfigurator.decode_yaml(hash_from_yaml)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should work with an XML config file' do
|
91
|
+
Log4r::Configurator.load_xml_file('spec/config_files/config.xml')
|
92
|
+
end
|
93
|
+
|
94
|
+
after(:each) do
|
95
|
+
outputter = Log4r::Outputter[outputter_name]
|
96
|
+
outputter.name.should eql(outputter_name)
|
97
|
+
Log4r::Logger[logger_name].outputters.should eql([outputter])
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log4r_remote_syslog_outputter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rob Hanlon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: log4r
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.9
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.9
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: remote_syslog_logger
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.7.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.7.0
|
62
|
+
description: The outputter included in this library simply ties Log4r's Outputter
|
63
|
+
interface together with remote_syslog_logger.
|
64
|
+
email:
|
65
|
+
- rob@mediapiston.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- Gemfile
|
73
|
+
- README
|
74
|
+
- Rakefile
|
75
|
+
- lib/log4r_remote_syslog_outputter.rb
|
76
|
+
- lib/log4r_remote_syslog_outputter/log4r/outputter/remote_syslog_outputter.rb
|
77
|
+
- lib/log4r_remote_syslog_outputter/version.rb
|
78
|
+
- log4r_remote_syslog_outputter.gemspec
|
79
|
+
- spec/config_files/config.xml
|
80
|
+
- spec/lib/log4r/logger_spec.rb
|
81
|
+
- spec/lib/log4r/outputter/remote_syslog_outputter_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: http://www.mediapiston.com/
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project: log4r_remote_syslog_outputter
|
103
|
+
rubygems_version: 1.8.24
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: A Log4r outputter that outputs via remote syslog
|
107
|
+
test_files:
|
108
|
+
- spec/config_files/config.xml
|
109
|
+
- spec/lib/log4r/logger_spec.rb
|
110
|
+
- spec/lib/log4r/outputter/remote_syslog_outputter_spec.rb
|
111
|
+
- spec/spec_helper.rb
|