logflume 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logflume/flume.rb +42 -34
- data/lib/logflume/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa73715ebd82ab4cb52b2b4bcd400bedf3289206
|
4
|
+
data.tar.gz: caa4cc54f5fdd7a32d7e28ac737262d8c67be3d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f82463b4a2b06c31961ce86a535e742d7fdcaafd13efa2341f6c3a9c675bdb50e38ef1d21422dffff4d4abe63cb145cf18849ace4dea0f3b2284e6bc7925f030
|
7
|
+
data.tar.gz: fc43a273af1c0c75169a5540ae88920862f58289421c22321148f261b9cd348d4a1c0eb4a5255435a7bcddf3d35259eb757b0a2c86a2433ddb6b04145f08f0d0
|
data/lib/logflume/flume.rb
CHANGED
@@ -26,19 +26,19 @@ module Logflume
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def load
|
29
|
-
raise InvalidDirectory unless
|
29
|
+
raise InvalidDirectory unless _directory_exists?(@dir)
|
30
30
|
if @shift
|
31
|
-
raise InvalidShiftDirectory unless
|
31
|
+
raise InvalidShiftDirectory unless _directory_exists?(@shift)
|
32
32
|
end
|
33
33
|
@dw = DirectoryWatcher.new(@dir, :glob => @glob, :logger => @logger, :interval => @interval, :pre_load => @pre_load)
|
34
34
|
@dw.persist = @bookmark if @bookmark
|
35
35
|
@configured = true unless @dw.nil?
|
36
|
-
|
36
|
+
_route_pipe
|
37
37
|
end
|
38
38
|
|
39
39
|
def start
|
40
40
|
load unless configured?
|
41
|
-
|
41
|
+
_register_signal_hooks
|
42
42
|
@dw.start
|
43
43
|
end
|
44
44
|
|
@@ -54,13 +54,13 @@ module Logflume
|
|
54
54
|
running? ? stop : true
|
55
55
|
@dw = nil
|
56
56
|
@configure = false
|
57
|
-
|
57
|
+
_destroy_pipe
|
58
58
|
true
|
59
59
|
end
|
60
60
|
|
61
61
|
private
|
62
62
|
|
63
|
-
def
|
63
|
+
def _register_signal_hooks
|
64
64
|
[:INT, :QUIT, :TERM].each do |signal|
|
65
65
|
::Signal.trap(signal) do
|
66
66
|
puts "Terminating..."
|
@@ -70,13 +70,13 @@ module Logflume
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
73
|
+
def _route_pipe
|
74
74
|
raise FlumeNotLoaded unless configured?
|
75
|
-
|
76
|
-
|
75
|
+
_create_pipe
|
76
|
+
_hookup_pipe
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
79
|
+
def _create_pipe
|
80
80
|
if @blocking
|
81
81
|
@pipe_handler = Fifo.new(@pipe, :w, :wait)
|
82
82
|
else
|
@@ -84,31 +84,47 @@ module Logflume
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
def
|
87
|
+
def _hookup_pipe
|
88
88
|
@dw.add_observer do |*args|
|
89
89
|
args.each do |event|
|
90
90
|
if event.type == :added
|
91
91
|
@logger.info "new File found => #{event.path}"
|
92
|
-
|
93
|
-
|
94
|
-
@pipe_handler.puts prefix + line
|
95
|
-
end
|
96
|
-
else
|
97
|
-
File.open(event.path).each_line do |line|
|
98
|
-
@pipe_handler.puts line
|
99
|
-
end
|
100
|
-
end
|
101
|
-
if @shift
|
102
|
-
@logger.info "shift # " + event.path + " -> " + @shift + '/' + File.basename(event.path)
|
103
|
-
File.rename(event.path, @shift + '/' + File.basename(event.path))
|
104
|
-
end
|
92
|
+
_print(event.path)
|
93
|
+
_shift(event.path) if @shift
|
105
94
|
end
|
106
95
|
|
107
96
|
end
|
108
97
|
end
|
109
98
|
end
|
110
99
|
|
111
|
-
def
|
100
|
+
def _destroy_pipe
|
101
|
+
::FileUtils.rm @pipe, :force => true
|
102
|
+
end
|
103
|
+
|
104
|
+
def _directory_exists?(directory)
|
105
|
+
File.directory?(directory)
|
106
|
+
end
|
107
|
+
|
108
|
+
def _print(event_file)
|
109
|
+
if @prefix_syslog
|
110
|
+
File.open(event_file).each_line do |line|
|
111
|
+
@pipe_handler.puts _prefix + line
|
112
|
+
end
|
113
|
+
else
|
114
|
+
File.open(event_file).each_line do |line|
|
115
|
+
@pipe_handler.puts line
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def _shift(event_file)
|
121
|
+
if @shift
|
122
|
+
@logger.info "shift # " + event_file + " -> " + @shift + '/' + File.basename(event_file)
|
123
|
+
File.rename(event_file, @shift + '/' + File.basename(event_file))
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def _prefix
|
112
128
|
mytime = Time.now
|
113
129
|
#template("$SOURCEIP|$FACILITY|$PRIORITY|$LEVEL|$TAG|$YEAR-$MONTH-$DAY|$HOUR:$MIN:$SEC|$PROGRAM| $MSG\n")
|
114
130
|
#@syslog_priority = @syslog_facility * 8 + @syslog_severity
|
@@ -118,16 +134,8 @@ module Logflume
|
|
118
134
|
return "#{@syslog_sourceip}|#{@syslog_facility}|#{@syslog_priority}|#{@syslog_level}|#{@tag}|#{ymd}|#{hms}|#{@syslog_progname}| "
|
119
135
|
end
|
120
136
|
|
121
|
-
def directory_exists?(directory)
|
122
|
-
File.directory?(directory)
|
123
|
-
end
|
124
|
-
|
125
|
-
def destroy_pipe
|
126
|
-
::FileUtils.rm @pipe, :force => true
|
127
|
-
end
|
128
|
-
|
129
137
|
# Borrowed from SyslogLogger.
|
130
|
-
def
|
138
|
+
def _clean(message)
|
131
139
|
message = message.to_s.dup
|
132
140
|
message.strip! # remove whitespace
|
133
141
|
message.gsub!(/\n/, '\\n') # escape newlines
|
data/lib/logflume/version.rb
CHANGED