tcp_syslog 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Changelog.md +3 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +37 -0
- data/Rakefile +54 -0
- data/lib/tcp_syslog.rb +180 -0
- data/tcp_syslog.gemspec +86 -0
- data/test/helper.rb +22 -0
- data/test/tcp_syslog_benchmark.rb +25 -0
- data/test/test_tcp_syslog.rb +76 -0
- metadata +246 -0
data/.document
ADDED
data/Changelog.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "yard", "~> 0.6.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.5.1"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
gem 'activesupport', '>=3.0.8'
|
15
|
+
gem "rr"
|
16
|
+
gem 'i18n'
|
17
|
+
gem 'SystemTimer'
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
SystemTimer (1.2.3)
|
5
|
+
activesupport (3.0.9)
|
6
|
+
git (1.2.5)
|
7
|
+
i18n (0.6.0)
|
8
|
+
jeweler (1.5.2)
|
9
|
+
bundler (~> 1.0.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.9)
|
14
|
+
rr (1.0.2)
|
15
|
+
shoulda (2.11.3)
|
16
|
+
yard (0.6.8)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
SystemTimer
|
23
|
+
activesupport (>= 3.0.8)
|
24
|
+
bundler (~> 1.0.0)
|
25
|
+
i18n
|
26
|
+
jeweler (~> 1.5.1)
|
27
|
+
rcov
|
28
|
+
rr
|
29
|
+
shoulda
|
30
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Tech-Angels SAS
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= tcp_syslog
|
2
|
+
|
3
|
+
Rails TCP syslog logger.
|
4
|
+
This logger sends logs to syslog using TCP instead of UDP.
|
5
|
+
This is much less efficient than logging to file, but required sometimes in large architectures.
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
=== Installation
|
10
|
+
|
11
|
+
Use bundle to install :
|
12
|
+
|
13
|
+
gem 'tcp_syslog'
|
14
|
+
|
15
|
+
=== Configuration
|
16
|
+
|
17
|
+
Add this line to your rails configuration :
|
18
|
+
|
19
|
+
config.logger = TcpSyslog.new(:progname => 'your_rails_app_name')
|
20
|
+
|
21
|
+
Options are detailled in doc.
|
22
|
+
|
23
|
+
== Contributing to tcp_syslog
|
24
|
+
|
25
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
26
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
27
|
+
* Fork the project
|
28
|
+
* Start a feature/bugfix branch
|
29
|
+
* Commit and push until you are happy with your contribution
|
30
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
31
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
32
|
+
|
33
|
+
== Copyright
|
34
|
+
|
35
|
+
Copyright (c) 2011 Tech-Angels SAS. See LICENSE.txt for
|
36
|
+
further details.
|
37
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "tcp_syslog"
|
16
|
+
gem.homepage = "http://github.com/tech-angels/tcp_syslog"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Send logs to syslog using TCP instead of UDP}
|
19
|
+
gem.description = %Q{Rails syslog logger using TCP instead of UDP}
|
20
|
+
gem.email = "philippe.lafoucriere@gmail.com"
|
21
|
+
gem.authors = ["Philippe Lafoucrière"]
|
22
|
+
gem.version = '1.0.0'
|
23
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
24
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
25
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
26
|
+
gem.add_runtime_dependency 'activesupport', '>=3.0.9'
|
27
|
+
gem.add_runtime_dependency 'SystemTimer', '>=1.2.3'
|
28
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rake/testtask'
|
33
|
+
Rake::TestTask.new(:test) do |test|
|
34
|
+
test.libs << 'lib' << 'test'
|
35
|
+
test.pattern = 'test/**/test_*.rb'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'rcov/rcovtask'
|
40
|
+
Rcov::RcovTask.new do |test|
|
41
|
+
test.libs << 'test'
|
42
|
+
test.pattern = 'test/**/test_*.rb'
|
43
|
+
test.verbose = true
|
44
|
+
end
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
Rake::TestTask.new(:benchmark) do |bm|
|
49
|
+
bm.libs << 'lib' << 'test'
|
50
|
+
bm.pattern = 'test/**/*_benchmark.rb'
|
51
|
+
bm.verbose = true
|
52
|
+
end
|
53
|
+
require 'yard'
|
54
|
+
YARD::Rake::YardocTask.new
|
data/lib/tcp_syslog.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'syslog'
|
3
|
+
require 'logger'
|
4
|
+
require 'system_timer'
|
5
|
+
|
6
|
+
# TcpSyslog is used are a dead-simple replacement for
|
7
|
+
# syslog ruby libs. None of them is able to send logs
|
8
|
+
# to a remote server, and even less in TCP.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# For rails (2.X) :
|
13
|
+
#
|
14
|
+
# config.logger = TcpSyslog.new(host => 'localhost')
|
15
|
+
#
|
16
|
+
# For more info about Syslog protocol, please refer to the RFC:
|
17
|
+
# http://www.faqs.org/rfcs/rfc3164.html
|
18
|
+
#
|
19
|
+
# Parts taken frm SyslogLogger gem and ActiveSupport
|
20
|
+
#
|
21
|
+
class TcpSyslog < ActiveSupport::BufferedLogger
|
22
|
+
include Logger::Severity
|
23
|
+
|
24
|
+
# From 'man syslog.h':
|
25
|
+
# LOG_EMERG A panic condition was reported to all processes.
|
26
|
+
# LOG_ALERT A condition that should be corrected immediately.
|
27
|
+
# LOG_CRIT A critical condition.
|
28
|
+
# LOG_ERR An error message.
|
29
|
+
# LOG_WARNING A warning message.
|
30
|
+
# LOG_NOTICE A condition requiring special handling.
|
31
|
+
# LOG_INFO A general information message.
|
32
|
+
# LOG_DEBUG A message useful for debugging programs.
|
33
|
+
|
34
|
+
# From logger rdoc:
|
35
|
+
# FATAL: an unhandleable error that results in a program crash
|
36
|
+
# ERROR: a handleable error condition
|
37
|
+
# WARN: a warning
|
38
|
+
# INFO: generic (useful) information about system operation
|
39
|
+
# DEBUG: low-level information for developers
|
40
|
+
|
41
|
+
# Maps Logger warning types to syslog(3) warning types.
|
42
|
+
LOGGER_MAP = {
|
43
|
+
:unknown => Syslog::LOG_ALERT,
|
44
|
+
:fatal => Syslog::LOG_CRIT,
|
45
|
+
:error => Syslog::LOG_ERR,
|
46
|
+
:warn => Syslog::LOG_WARNING,
|
47
|
+
:info => Syslog::LOG_INFO,
|
48
|
+
:debug => Syslog::LOG_DEBUG
|
49
|
+
}
|
50
|
+
|
51
|
+
# Maps Logger log levels to their values so we can silence.
|
52
|
+
LOGGER_LEVEL_MAP = {}
|
53
|
+
|
54
|
+
LOGGER_MAP.each_key do |key|
|
55
|
+
LOGGER_LEVEL_MAP[key] = Logger.const_get key.to_s.upcase
|
56
|
+
end
|
57
|
+
|
58
|
+
# Maps Logger log level values to syslog log levels.
|
59
|
+
LEVEL_LOGGER_MAP = {}
|
60
|
+
|
61
|
+
LOGGER_LEVEL_MAP.invert.each do |level, severity|
|
62
|
+
LEVEL_LOGGER_MAP[level] = LOGGER_MAP[severity]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Usage :
|
66
|
+
# * +options+ : A hash with the following options
|
67
|
+
# ** +host+ : defaults to 'localhost'
|
68
|
+
# ** +port+ : defaults to '514'
|
69
|
+
# ** +facility+ : defaults to user
|
70
|
+
# ** +progname+ : defaults to 'rails'
|
71
|
+
# ** +auto_flushing+ : number of messages to buffer before flushing
|
72
|
+
#
|
73
|
+
def initialize(options = {})
|
74
|
+
@level = LOGGER_LEVEL_MAP[options[:level]] || Logger::DEBUG
|
75
|
+
@host = options[:host] || 'localhost'
|
76
|
+
@port = options[:port] = '514'
|
77
|
+
@facility = options[:facility] || Syslog::LOG_USER
|
78
|
+
@progname = options[:progname] || 'rails'
|
79
|
+
@buffer = Hash.new { |h,k| h[k] = [] }
|
80
|
+
@socket = {}
|
81
|
+
@auto_flushing = options[:auto_flushing] || 1
|
82
|
+
@local_ip = local_ip
|
83
|
+
@remove_ansi_colors = options[:remove_ansi_colors] || true
|
84
|
+
return if defined? SYSLOG
|
85
|
+
self.class.const_set :SYSLOG, true
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
# Log level for Logger compatibility.
|
90
|
+
attr_reader :host, :port, :facility, :auto_flushing, :progname
|
91
|
+
# Check ActiveSupport::BufferedLogger for other attributes
|
92
|
+
|
93
|
+
# Almost duplicates Logger#add.
|
94
|
+
def add(severity, message, progname = nil, &block)
|
95
|
+
severity ||= Logger::UNKNOWN
|
96
|
+
return if @level > severity
|
97
|
+
message = clean(message || block.call)
|
98
|
+
buffer << {:severity => severity, :body => clean(message)}
|
99
|
+
auto_flush
|
100
|
+
message
|
101
|
+
end
|
102
|
+
|
103
|
+
# In Logger, this dumps the raw message; the closest equivalent
|
104
|
+
# would be Logger::UNKNOWN
|
105
|
+
def <<(message)
|
106
|
+
add(Logger::UNKNOWN, message)
|
107
|
+
end
|
108
|
+
|
109
|
+
def close
|
110
|
+
flush
|
111
|
+
socket.close
|
112
|
+
@socket[Thread.current] = nil
|
113
|
+
end
|
114
|
+
|
115
|
+
# Flush buffered logs to Syslog
|
116
|
+
def flush
|
117
|
+
buffer.each do |message|
|
118
|
+
log(message[:severity], message[:body])
|
119
|
+
end
|
120
|
+
clear_buffer
|
121
|
+
end
|
122
|
+
|
123
|
+
def socket
|
124
|
+
@socket[Thread.current] ||= TCPSocket.new(@host, @port)
|
125
|
+
end
|
126
|
+
|
127
|
+
protected
|
128
|
+
|
129
|
+
# Clean up messages so they're nice and pretty.
|
130
|
+
def clean(message)
|
131
|
+
message = message.to_s.dup
|
132
|
+
message.strip!
|
133
|
+
message.gsub!(/%/, '%%') # syslog(3) freaks on % (printf)
|
134
|
+
message.gsub!(/\e\[[^m]*m/, '') if @remove_ansi_colors # remove useless ansi color codes
|
135
|
+
return message
|
136
|
+
end
|
137
|
+
|
138
|
+
# Returns current ip
|
139
|
+
# (taken from http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/)
|
140
|
+
def local_ip
|
141
|
+
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily
|
142
|
+
|
143
|
+
UDPSocket.open do |s|
|
144
|
+
s.connect '64.233.187.99', 1
|
145
|
+
s.addr.last
|
146
|
+
end
|
147
|
+
ensure
|
148
|
+
Socket.do_not_reverse_lookup = orig
|
149
|
+
end
|
150
|
+
|
151
|
+
# Log the message to syslog
|
152
|
+
# This method is private, use the +add+ method instead
|
153
|
+
def log(severity, msg)
|
154
|
+
begin
|
155
|
+
# Newline characters are not allowed in MSG part
|
156
|
+
msg.split("\n").each do |line|
|
157
|
+
write_on_socket(severity, line)
|
158
|
+
end
|
159
|
+
rescue Errno::ECONNREFUSED, Errno::EPIPE, Timeout::Error => e
|
160
|
+
# can't log anything, stop trying
|
161
|
+
@socket[Thread.current] = nil
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# actually write on the tcp socket
|
166
|
+
def write_on_socket(severity, msg)
|
167
|
+
SystemTimer.timeout_after(1) do
|
168
|
+
# Build syslog packet
|
169
|
+
packet = "<#{@facility + LEVEL_LOGGER_MAP[severity]}>#{Time.now.strftime("%b %e %H:%M:%S")} #{@local_ip} [#{@progname}]: #{msg}\n"
|
170
|
+
# Max size of a packet cannot be greater than 1024 bytes
|
171
|
+
if packet.size > 1024 # FIXME1.9: use bytesize, fix following 2 lines
|
172
|
+
socket.write(packet[0..1022] + "\n")
|
173
|
+
write_on_socket severity, packet[1023..-1]
|
174
|
+
else
|
175
|
+
socket.write(packet)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
data/tcp_syslog.gemspec
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tcp_syslog}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Philippe Lafoucri\303\250re"]
|
12
|
+
s.date = %q{2011-06-17}
|
13
|
+
s.description = %q{Rails syslog logger using TCP instead of UDP}
|
14
|
+
s.email = %q{philippe.lafoucriere@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Changelog.md",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"lib/tcp_syslog.rb",
|
28
|
+
"tcp_syslog.gemspec",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/tcp_syslog_benchmark.rb",
|
31
|
+
"test/test_tcp_syslog.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/tech-angels/tcp_syslog}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.5.2}
|
37
|
+
s.summary = %q{Send logs to syslog using TCP instead of UDP}
|
38
|
+
s.test_files = [
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/tcp_syslog_benchmark.rb",
|
41
|
+
"test/test_tcp_syslog.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
|
52
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<activesupport>, [">= 3.0.8"])
|
54
|
+
s.add_development_dependency(%q<rr>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<i18n>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<SystemTimer>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.9"])
|
58
|
+
s.add_runtime_dependency(%q<SystemTimer>, [">= 1.2.3"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.8"])
|
66
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
67
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
68
|
+
s.add_dependency(%q<SystemTimer>, [">= 0"])
|
69
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.9"])
|
70
|
+
s.add_dependency(%q<SystemTimer>, [">= 1.2.3"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
74
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
75
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
|
77
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
78
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.8"])
|
79
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
80
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
81
|
+
s.add_dependency(%q<SystemTimer>, [">= 0"])
|
82
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.9"])
|
83
|
+
s.add_dependency(%q<SystemTimer>, [">= 1.2.3"])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
require 'rr'
|
13
|
+
require 'active_support'
|
14
|
+
require 'timeout'
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
18
|
+
require 'tcp_syslog'
|
19
|
+
|
20
|
+
class Test::Unit::TestCase
|
21
|
+
include RR::Adapters::TestUnit
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
logger_tcp = TcpSyslog.new
|
5
|
+
logger_file = ActiveSupport::BufferedLogger.new("/tmp/logfile")
|
6
|
+
|
7
|
+
Benchmark.bm do |b|
|
8
|
+
b.report("File (100 times)") do
|
9
|
+
100.times { logger_file.info("benchmark") }
|
10
|
+
end
|
11
|
+
|
12
|
+
b.report("TCP (100 times)") do
|
13
|
+
100.times { logger_tcp.info("benchmark") }
|
14
|
+
end
|
15
|
+
|
16
|
+
logger_file.auto_flushing = 20
|
17
|
+
b.report("File (100 times, buffer = 20)") do
|
18
|
+
100.times { logger_file.info("benchmark") }
|
19
|
+
end
|
20
|
+
|
21
|
+
logger_tcp.auto_flushing = 20
|
22
|
+
b.report("TCP (100 times, buffer = 20)") do
|
23
|
+
100.times { logger_tcp.info("benchmark") }
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestTcpSyslog < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
context "A TcpSyslogger" do
|
6
|
+
setup do
|
7
|
+
@logger = TcpSyslog.new
|
8
|
+
end
|
9
|
+
|
10
|
+
should "have set defaults correctly" do
|
11
|
+
assert_equal 'localhost', @logger.host
|
12
|
+
assert_equal '514', @logger.port
|
13
|
+
assert_equal Syslog::LOG_USER, @logger.facility
|
14
|
+
assert_equal 'rails', @logger.progname
|
15
|
+
assert_equal 1, @logger.auto_flushing
|
16
|
+
assert_equal Logger::DEBUG, @logger.level
|
17
|
+
end
|
18
|
+
|
19
|
+
should "have defined debug, info, warn, error, fatal methods" do
|
20
|
+
assert @logger.respond_to?(:debug)
|
21
|
+
assert @logger.respond_to?(:info)
|
22
|
+
assert @logger.respond_to?(:warn)
|
23
|
+
assert @logger.respond_to?(:error)
|
24
|
+
assert @logger.respond_to?(:fatal)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "on add message" do
|
28
|
+
setup do
|
29
|
+
message = "This message to be sent to syslog"
|
30
|
+
mock.proxy(@logger).flush
|
31
|
+
mock.proxy(@logger).log(Logger::INFO, message)
|
32
|
+
mock.proxy(@logger).write_on_socket(Logger::INFO, message)
|
33
|
+
@logger.add(Logger::INFO, message)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "have sent the message to syslog" do
|
37
|
+
RR.verify
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "A TcpSyslogger with auto_flushing set to 2" do
|
43
|
+
setup do
|
44
|
+
@logger = TcpSyslog.new(:auto_flushing => 2)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "have set auto_flushing to 2" do
|
48
|
+
assert_equal 2, @logger.auto_flushing
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when adding a message" do
|
52
|
+
setup do
|
53
|
+
message = "info message"
|
54
|
+
dont_allow(@logger).write_on_socket(Logger::INFO, message)
|
55
|
+
@logger.info(message)
|
56
|
+
end
|
57
|
+
|
58
|
+
should "not send the message to syslog now" do
|
59
|
+
RR.verify
|
60
|
+
end
|
61
|
+
|
62
|
+
context "and adding another message" do
|
63
|
+
setup do
|
64
|
+
message2 = "info message 2"
|
65
|
+
RR.reset
|
66
|
+
mock.proxy(@logger).write_on_socket(Logger::INFO, anything).twice
|
67
|
+
@logger.info(message2)
|
68
|
+
end
|
69
|
+
|
70
|
+
should "have sent the messages to syslog" do
|
71
|
+
RR.verify
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tcp_syslog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Philippe Lafoucri\xC3\xA8re"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-17 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
name: shoulda
|
33
|
+
version_requirements: *id001
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 7
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 6
|
46
|
+
- 0
|
47
|
+
version: 0.6.0
|
48
|
+
name: yard
|
49
|
+
version_requirements: *id002
|
50
|
+
prerelease: false
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
type: :development
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 23
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
version: 1.0.0
|
64
|
+
name: bundler
|
65
|
+
version_requirements: *id003
|
66
|
+
prerelease: false
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 1
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 5
|
78
|
+
- 1
|
79
|
+
version: 1.5.1
|
80
|
+
name: jeweler
|
81
|
+
version_requirements: *id004
|
82
|
+
prerelease: false
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
type: :development
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
name: rcov
|
95
|
+
version_requirements: *id005
|
96
|
+
prerelease: false
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
type: :development
|
99
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 23
|
105
|
+
segments:
|
106
|
+
- 3
|
107
|
+
- 0
|
108
|
+
- 8
|
109
|
+
version: 3.0.8
|
110
|
+
name: activesupport
|
111
|
+
version_requirements: *id006
|
112
|
+
prerelease: false
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
type: :development
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
name: rr
|
125
|
+
version_requirements: *id007
|
126
|
+
prerelease: false
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
type: :development
|
129
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
name: i18n
|
139
|
+
version_requirements: *id008
|
140
|
+
prerelease: false
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
type: :development
|
143
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 3
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
name: SystemTimer
|
153
|
+
version_requirements: *id009
|
154
|
+
prerelease: false
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
type: :runtime
|
157
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
hash: 21
|
163
|
+
segments:
|
164
|
+
- 3
|
165
|
+
- 0
|
166
|
+
- 9
|
167
|
+
version: 3.0.9
|
168
|
+
name: activesupport
|
169
|
+
version_requirements: *id010
|
170
|
+
prerelease: false
|
171
|
+
- !ruby/object:Gem::Dependency
|
172
|
+
type: :runtime
|
173
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
174
|
+
none: false
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
hash: 25
|
179
|
+
segments:
|
180
|
+
- 1
|
181
|
+
- 2
|
182
|
+
- 3
|
183
|
+
version: 1.2.3
|
184
|
+
name: SystemTimer
|
185
|
+
version_requirements: *id011
|
186
|
+
prerelease: false
|
187
|
+
description: Rails syslog logger using TCP instead of UDP
|
188
|
+
email: philippe.lafoucriere@gmail.com
|
189
|
+
executables: []
|
190
|
+
|
191
|
+
extensions: []
|
192
|
+
|
193
|
+
extra_rdoc_files:
|
194
|
+
- LICENSE.txt
|
195
|
+
- README.rdoc
|
196
|
+
files:
|
197
|
+
- .document
|
198
|
+
- Changelog.md
|
199
|
+
- Gemfile
|
200
|
+
- Gemfile.lock
|
201
|
+
- LICENSE.txt
|
202
|
+
- README.rdoc
|
203
|
+
- Rakefile
|
204
|
+
- lib/tcp_syslog.rb
|
205
|
+
- tcp_syslog.gemspec
|
206
|
+
- test/helper.rb
|
207
|
+
- test/tcp_syslog_benchmark.rb
|
208
|
+
- test/test_tcp_syslog.rb
|
209
|
+
has_rdoc: true
|
210
|
+
homepage: http://github.com/tech-angels/tcp_syslog
|
211
|
+
licenses:
|
212
|
+
- MIT
|
213
|
+
post_install_message:
|
214
|
+
rdoc_options: []
|
215
|
+
|
216
|
+
require_paths:
|
217
|
+
- lib
|
218
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
none: false
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
hash: 3
|
224
|
+
segments:
|
225
|
+
- 0
|
226
|
+
version: "0"
|
227
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
|
+
none: false
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
hash: 3
|
233
|
+
segments:
|
234
|
+
- 0
|
235
|
+
version: "0"
|
236
|
+
requirements: []
|
237
|
+
|
238
|
+
rubyforge_project:
|
239
|
+
rubygems_version: 1.5.2
|
240
|
+
signing_key:
|
241
|
+
specification_version: 3
|
242
|
+
summary: Send logs to syslog using TCP instead of UDP
|
243
|
+
test_files:
|
244
|
+
- test/helper.rb
|
245
|
+
- test/tcp_syslog_benchmark.rb
|
246
|
+
- test/test_tcp_syslog.rb
|