Skip to content

Commit 8fc8278

Browse files
committed
initial commit
1 parent 7e23a2f commit 8fc8278

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source :gemcutter
2+
gem 'carrot'
3+
gem 'choice'

README

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apache amqp message bus based logger.
2+
3+
Put the following in your apache config:
4+
5+
6+
CustomLog "|/usr/local/logspray/bin/apache_netlogger.rb --host=myamqploghost --queue=apache_access_log" combined
7+
ErrorLog "|/usr/local/logspray/bin/apache_netlogger.rb --host=myamqploghost --queue=apache_error_log"
8+
9+
10+
11+
on your logserver:
12+
13+
14+
add this cronjob:
15+
16+
17+
* * * * * ruby /usr/local/logspray/bin/consume_apache_netlogger.rb --host=myamqploghost --queue=apache_access_log
18+
* * * * * ruby /usr/local/logspray/bin/consume_apache_netlogger.rb --host=myamqploghost --queue=apache_error_log

bin/consume_logspray_queue.rb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env ruby
2+
3+
=begin
4+
Copyright (c) 2010 David Andersen | davidx.org | davidx at davidx.org
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
=end
24+
25+
26+
require 'rubygems'
27+
require 'carrot'
28+
require 'choice'
29+
require 'date'
30+
require 'fileutils'
31+
32+
Choice.options do
33+
header ''
34+
header 'Specific options:'
35+
36+
option :host, :required => true do
37+
short '-host'
38+
long '--host=HOST'
39+
desc 'The hostname or ip of the amqp server (required)'
40+
end
41+
42+
option :queue, :required => true do
43+
short '-q'
44+
long '--queue=QUEUE'
45+
desc 'The queue'
46+
end
47+
option :logfile, :required => true do
48+
short '-f'
49+
long '--logfile=LOGFILE'
50+
desc 'The logfile to output to'
51+
end
52+
option :logdir do
53+
short '-d'
54+
long '--logdir=LOGDIR'
55+
desc 'The logdir to use'
56+
default '/var/log/logspray'
57+
end
58+
separator ''
59+
separator 'Common options: '
60+
61+
option :help do
62+
long '--help'
63+
desc 'Show this message'
64+
end
65+
end
66+
67+
DATE=DateTime.now.strftime("%Y%m%d")
68+
HOST = Choice.choices[:host]
69+
QUEUE = Choice.choices[:queue]
70+
LOGDIR = Choice.choices[:logdir]
71+
LOGFILE = Choice.choices[:logfile] || "#{DEFAULT_LOGDIR}/#{QUEUE}/#{DATE}_#{QUEUE}.log"
72+
73+
FileUtils.mkdir_p(File.dirname(LOGFILE))
74+
75+
client = Carrot.new(:host => HOST)
76+
q = client.queue(QUEUE)
77+
78+
file = File.open(LOGFILE, "a")
79+
while msg = q.pop(:ack => true)
80+
file.syswrite(msg)
81+
q.ack
82+
end
83+
file.close
84+
Carrot.stop
85+

bin/logspray.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/ruby
2+
3+
require 'rubygems'
4+
require 'carrot'
5+
require 'choice'
6+
7+
Choice.options do
8+
header ''
9+
header 'Specific options:'
10+
11+
option :host, :required =>true do
12+
short '-h'
13+
long '--host=HOST'
14+
desc 'The hostname or ip of the amqp server (required)'
15+
default '10.10.10.100'
16+
end
17+
18+
option :queue,:required =>true do
19+
short '-q'
20+
long '--queue=QUEUE'
21+
desc 'The queue'
22+
end
23+
24+
separator ''
25+
separator 'Common options: '
26+
27+
option :help do
28+
long '--help'
29+
desc 'Show this message'
30+
end
31+
end
32+
33+
HOST = Choice.choices[:host]
34+
QUEUE = Choice.choices[:queue]
35+
36+
client = Carrot.new(:host => HOST)
37+
q = client.queue(QUEUE)
38+
while (line = $stdin.gets) do
39+
q.publish(line)
40+
end

0 commit comments

Comments
 (0)