remote_syslog_logger 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +63 -0
- data/Rakefile +150 -0
- data/lib/remote_syslog_logger.rb +11 -0
- data/lib/remote_syslog_logger/udp_sender.rb +35 -0
- data/remote_syslog_logger.gemspec +77 -0
- data/test/helper.rb +12 -0
- data/test/test_remote_syslog_logger.rb +18 -0
- metadata +89 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Eric Lindvall
|
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,63 @@
|
|
1
|
+
# Remote Syslog Logger
|
2
|
+
|
3
|
+
This library providers an [ActiveSupport][] compatible logger that logs
|
4
|
+
directly to a remote syslogd via UDP.
|
5
|
+
|
6
|
+
[ActiveSupport]: http://as.rubyonrails.org/
|
7
|
+
|
8
|
+
|
9
|
+
# Installation
|
10
|
+
|
11
|
+
The easiest way to install `remote_syslog_logger` is with RubyGems:
|
12
|
+
|
13
|
+
$ [sudo] gem install remote_syslog_logger
|
14
|
+
|
15
|
+
|
16
|
+
# Usage
|
17
|
+
|
18
|
+
|
19
|
+
Use from Rails:
|
20
|
+
|
21
|
+
config.logger = RemoteSyslogLogger.new('syslog.domain.com', 514, :program => "rails-#{RAILS_ENV}")
|
22
|
+
|
23
|
+
|
24
|
+
Use from Ruby:
|
25
|
+
|
26
|
+
$logger = RemoteSyslogLogger.new('syslog.domain.com', 514)
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
# Source
|
31
|
+
|
32
|
+
Remote Syslog Logger is available on GitHub, which can be browsed at:
|
33
|
+
|
34
|
+
<http://github.com/eric/remote_syslog_logger>
|
35
|
+
|
36
|
+
and cloned with:
|
37
|
+
|
38
|
+
$ git clone git://github.com/eric/remote_syslog_logger.git
|
39
|
+
|
40
|
+
|
41
|
+
# Contributing
|
42
|
+
|
43
|
+
Once you've made your great commits:
|
44
|
+
|
45
|
+
1. [Fork][fk] `remote_syslog_logger`
|
46
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
47
|
+
3. Push to your branch - `git push origin my_branch`
|
48
|
+
4. Create a Pull Request or an [Issue][is] with a link to your branch
|
49
|
+
5. That's it!
|
50
|
+
|
51
|
+
You might want to checkout Resque's [Contributing][cb] wiki page for information
|
52
|
+
on coding standards, new features, etc.
|
53
|
+
|
54
|
+
|
55
|
+
# License
|
56
|
+
|
57
|
+
Copyright (c) 2011 Eric Lindvall. See [LICENSE][] for details.
|
58
|
+
|
59
|
+
|
60
|
+
[cb]: https://wiki.github.com/defunkt/resque/contributing
|
61
|
+
[fk]: http://help.github.com/forking/
|
62
|
+
[is]: https://github.com/eric/remote_syslog_logger/issues
|
63
|
+
[LICENSE]: https://github.com/eric/remote_syslog_logger/blob/master/LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
Date.today.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def rubyforge_project
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
def gemspec_file
|
29
|
+
"#{name}.gemspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gem_file
|
33
|
+
"#{name}-#{version}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_header(head, header_name)
|
37
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
+
end
|
39
|
+
|
40
|
+
#############################################################################
|
41
|
+
#
|
42
|
+
# Standard tasks
|
43
|
+
#
|
44
|
+
#############################################################################
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/testtask'
|
49
|
+
Rake::TestTask.new(:test) do |test|
|
50
|
+
test.libs << 'lib' << 'test'
|
51
|
+
test.pattern = 'test/**/test_*.rb'
|
52
|
+
test.verbose = true
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Generate RCov test coverage and open in your browser"
|
56
|
+
task :coverage do
|
57
|
+
require 'rcov'
|
58
|
+
sh "rm -fr coverage"
|
59
|
+
sh "rcov test/test_*.rb"
|
60
|
+
sh "open coverage/index.html"
|
61
|
+
end
|
62
|
+
|
63
|
+
require 'rake/rdoctask'
|
64
|
+
Rake::RDocTask.new do |rdoc|
|
65
|
+
rdoc.rdoc_dir = 'rdoc'
|
66
|
+
rdoc.title = "#{name} #{version}"
|
67
|
+
rdoc.rdoc_files.include('README*')
|
68
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Open an irb session preloaded with this library"
|
72
|
+
task :console do
|
73
|
+
sh "irb -rubygems -r ./lib/#{name}.rb"
|
74
|
+
end
|
75
|
+
|
76
|
+
#############################################################################
|
77
|
+
#
|
78
|
+
# Custom tasks (add your own tasks here)
|
79
|
+
#
|
80
|
+
#############################################################################
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
#############################################################################
|
85
|
+
#
|
86
|
+
# Packaging tasks
|
87
|
+
#
|
88
|
+
#############################################################################
|
89
|
+
|
90
|
+
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
91
|
+
task :release => :build do
|
92
|
+
unless `git branch` =~ /^\* master$/
|
93
|
+
puts "You must be on the master branch to release!"
|
94
|
+
exit!
|
95
|
+
end
|
96
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
97
|
+
sh "git tag v#{version}"
|
98
|
+
sh "git push origin master"
|
99
|
+
sh "git push origin v#{version}"
|
100
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
101
|
+
end
|
102
|
+
|
103
|
+
desc "Build #{gem_file} into the pkg directory"
|
104
|
+
task :build => :gemspec do
|
105
|
+
sh "mkdir -p pkg"
|
106
|
+
sh "gem build #{gemspec_file}"
|
107
|
+
sh "mv #{gem_file} pkg"
|
108
|
+
end
|
109
|
+
|
110
|
+
desc "Generate #{gemspec_file}"
|
111
|
+
task :gemspec => :validate do
|
112
|
+
# read spec file and split out manifest section
|
113
|
+
spec = File.read(gemspec_file)
|
114
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
115
|
+
|
116
|
+
# replace name version and date
|
117
|
+
replace_header(head, :name)
|
118
|
+
replace_header(head, :version)
|
119
|
+
replace_header(head, :date)
|
120
|
+
#comment this out if your rubyforge_project has a different name
|
121
|
+
replace_header(head, :rubyforge_project)
|
122
|
+
|
123
|
+
# determine file list from git ls-files
|
124
|
+
files = `git ls-files`.
|
125
|
+
split("\n").
|
126
|
+
sort.
|
127
|
+
reject { |file| file =~ /^\./ }.
|
128
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
129
|
+
map { |file| " #{file}" }.
|
130
|
+
join("\n")
|
131
|
+
|
132
|
+
# piece file back together and write
|
133
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
134
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
135
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
136
|
+
puts "Updated #{gemspec_file}"
|
137
|
+
end
|
138
|
+
|
139
|
+
desc "Validate #{gemspec_file}"
|
140
|
+
task :validate do
|
141
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
142
|
+
unless libfiles.empty?
|
143
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
144
|
+
exit!
|
145
|
+
end
|
146
|
+
unless Dir['VERSION*'].empty?
|
147
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
148
|
+
exit!
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
|
2
|
+
require 'remote_syslog_logger/udp_sender'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module RemoteSyslogLogger
|
6
|
+
VERSION = '1.0.0'
|
7
|
+
|
8
|
+
def self.new(remote_hostname, remote_port, options = {})
|
9
|
+
Logger.new(RemoteSyslogLogger::UdpSender.new(remote_hostname, remote_port, options))
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'syslog_protocol'
|
3
|
+
|
4
|
+
module RemoteSyslogLogger
|
5
|
+
class UdpSender
|
6
|
+
def initialize(remote_hostname, remote_port, options = {})
|
7
|
+
@remote_hostname = remote_hostname
|
8
|
+
@remote_port = remote_port
|
9
|
+
|
10
|
+
@socket = UDPSocket.new
|
11
|
+
@packet = SyslogProtocol::Packet.new
|
12
|
+
|
13
|
+
local_hostname = options[:local_hostname] || (Socket.gethostname rescue `hostname`.chomp)
|
14
|
+
local_hostname = 'localhost' if local_hostname.nil? || local_hostname.empty?
|
15
|
+
@packet.hostname = local_hostname
|
16
|
+
|
17
|
+
@packet.facility = options[:facility] || 'user'
|
18
|
+
@packet.severity = options[:severity] || 'notice'
|
19
|
+
@packet.tag = options[:program] || "#{File.basename($0)}[#{$$}]"
|
20
|
+
end
|
21
|
+
|
22
|
+
def transmit(message)
|
23
|
+
packet = @packet.dup
|
24
|
+
packet.content = message
|
25
|
+
@socket.send(packet.assemble, 0, @remote_hostname, @remote_port)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Make this act a little bit like an `IO` object
|
29
|
+
alias_method :write, :transmit
|
30
|
+
|
31
|
+
def close
|
32
|
+
@socket.close
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
+
## all of the comments. Some sections require modification, and others can
|
3
|
+
## be deleted if you don't need them. Once you understand the contents of
|
4
|
+
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
+
## You can find comprehensive Gem::Specification documentation, at
|
6
|
+
## http://docs.rubygems.org/read/chapter/20
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.rubygems_version = '1.3.5'
|
11
|
+
|
12
|
+
## Leave these as is they will be modified for you by the rake gemspec task.
|
13
|
+
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
+
## the sub! line in the Rakefile
|
15
|
+
s.name = 'remote_syslog_logger'
|
16
|
+
s.version = '1.0.0'
|
17
|
+
s.date = '2011-03-28'
|
18
|
+
# s.rubyforge_project = 'remote_syslog_logger'
|
19
|
+
|
20
|
+
## Make sure your summary is short. The description may be as long
|
21
|
+
## as you like.
|
22
|
+
s.summary = "Ruby Logger that sends directly to a remote syslog endpoint"
|
23
|
+
s.description = "A ruby Logger that sends UDP directly to a remote syslog endpoint"
|
24
|
+
|
25
|
+
## List the primary authors. If there are a bunch of authors, it's probably
|
26
|
+
## better to set the email to an email list or something. If you don't have
|
27
|
+
## a custom homepage, consider using your GitHub URL or the like.
|
28
|
+
s.authors = ["Eric Lindvall"]
|
29
|
+
s.email = 'eric@5stops.com'
|
30
|
+
s.homepage = 'http://github.com/eric/remote_syslog_logger'
|
31
|
+
|
32
|
+
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
|
+
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
34
|
+
s.require_paths = %w[lib]
|
35
|
+
|
36
|
+
## This sections is only necessary if you have C extensions.
|
37
|
+
# s.require_paths << 'ext'
|
38
|
+
# s.extensions = %w[ext/extconf.rb]
|
39
|
+
|
40
|
+
## If your gem includes any executables, list them here.
|
41
|
+
# s.executables = ["name"]
|
42
|
+
# s.default_executable = 'name'
|
43
|
+
|
44
|
+
## Specify any RDoc options here. You'll want to add your README and
|
45
|
+
## LICENSE files to the extra_rdoc_files list.
|
46
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
47
|
+
s.extra_rdoc_files = %w[README.md LICENSE]
|
48
|
+
|
49
|
+
## List your runtime dependencies here. Runtime dependencies are those
|
50
|
+
## that are needed for an end user to actually USE your code.
|
51
|
+
s.add_dependency('syslog_protocol')
|
52
|
+
|
53
|
+
## List your development dependencies here. Development dependencies are
|
54
|
+
## those that are only needed during development
|
55
|
+
# s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
|
56
|
+
|
57
|
+
## Leave this section as-is. It will be automatically generated from the
|
58
|
+
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
59
|
+
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
60
|
+
# = MANIFEST =
|
61
|
+
s.files = %w[
|
62
|
+
Gemfile
|
63
|
+
LICENSE
|
64
|
+
README.md
|
65
|
+
Rakefile
|
66
|
+
lib/remote_syslog_logger.rb
|
67
|
+
lib/remote_syslog_logger/udp_sender.rb
|
68
|
+
remote_syslog_logger.gemspec
|
69
|
+
test/helper.rb
|
70
|
+
test/test_remote_syslog_logger.rb
|
71
|
+
]
|
72
|
+
# = MANIFEST =
|
73
|
+
|
74
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
75
|
+
## matches what you actually use.
|
76
|
+
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
77
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class TestRemoteSyslogLogger < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@server_port = rand(50000) + 1024
|
6
|
+
@socket = UDPSocket.new
|
7
|
+
@socket.bind('127.0.0.1', @server_port)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_logger
|
11
|
+
@logger = RemoteSyslogLogger.new('127.0.0.1', @server_port)
|
12
|
+
@logger.info "This is a test"
|
13
|
+
|
14
|
+
message, addr = *@socket.recvfrom(1024)
|
15
|
+
puts message
|
16
|
+
assert_match /This is a test/, message
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remote_syslog_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Eric Lindvall
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-28 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: syslog_protocol
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: A ruby Logger that sends UDP directly to a remote syslog endpoint
|
36
|
+
email: eric@5stops.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.md
|
43
|
+
- LICENSE
|
44
|
+
files:
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- lib/remote_syslog_logger.rb
|
50
|
+
- lib/remote_syslog_logger/udp_sender.rb
|
51
|
+
- remote_syslog_logger.gemspec
|
52
|
+
- test/helper.rb
|
53
|
+
- test/test_remote_syslog_logger.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/eric/remote_syslog_logger
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
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
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 2
|
87
|
+
summary: Ruby Logger that sends directly to a remote syslog endpoint
|
88
|
+
test_files:
|
89
|
+
- test/test_remote_syslog_logger.rb
|