logfile_transfer 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +120 -2
- data/example.rb +12 -9
- data/lib/logfile_transfer.rb +7 -4
- 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: 4914ab9a1824adcccd09061b5eee099adb8c3ff5
|
4
|
+
data.tar.gz: 8d4e300d76457bdd638f72331d6160669b9af930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 642bf372fbc1e02bf0c6f198788eec3509a38cb832cb48d8db353a5b218f4cafa4ef4845b0355564e40e9b63a1f12a4be31fbedcb920104c25f26f35cdd42eb5
|
7
|
+
data.tar.gz: f12ecc714799ce3e276d22d9d14fc010b66847cc79e8b379f655cfa3101303d9d8e0d0e3858add38288e1baf5004df6db9d5500f474c9d10eb05598637ae30d0
|
data/README.md
CHANGED
@@ -1,5 +1,123 @@
|
|
1
|
-
|
2
|
-
================
|
1
|
+
# Logfile Transfer
|
3
2
|
|
4
3
|
Ruby monitoring and transform logfiles daemon.
|
5
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install logfile_transfer
|
8
|
+
# you may need to run:
|
9
|
+
sudo gem install logfile_transfer
|
10
|
+
|
11
|
+
## Examples
|
12
|
+
|
13
|
+
### Edit example.rb
|
14
|
+
|
15
|
+
require 'logfile_transfer'
|
16
|
+
|
17
|
+
class Test < LogfileTransfer::Handler
|
18
|
+
|
19
|
+
def init
|
20
|
+
@test_log_file = File.new '/tmp/test.log', 'a'
|
21
|
+
@test_log_file.sync = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def handle log_path, log_fn, line, line_count, pattern
|
25
|
+
@test_log_file.puts "#{log_path}, #{log_fn}, #{line_count}, #{pattern}"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# The daemon binding on port 2001, make it different in other daemon
|
31
|
+
LogfileTransfer.run ARGV, 2001, File.expand_path(File.dirname(__FILE__))
|
32
|
+
|
33
|
+
### Edit config.yaml
|
34
|
+
|
35
|
+
---
|
36
|
+
- !ruby/object:LogfileTransfer::FileMonitorObj
|
37
|
+
absolute_path: /data/webroot/log
|
38
|
+
dir_disallow: []
|
39
|
+
file_disallow:
|
40
|
+
- .*
|
41
|
+
file_allow:
|
42
|
+
- \.log\.
|
43
|
+
patterns:
|
44
|
+
- - .*
|
45
|
+
- - !ruby/object:Test {}
|
46
|
+
|
47
|
+
## Run
|
48
|
+
|
49
|
+
# as root user, run:
|
50
|
+
Ruby example.rb start
|
51
|
+
# you may need to run:
|
52
|
+
sudo Ruby example.rb start
|
53
|
+
|
54
|
+
## Status
|
55
|
+
|
56
|
+
Ruby example.rb status
|
57
|
+
|
58
|
+
## Stop
|
59
|
+
|
60
|
+
Ruby example.rb stop
|
61
|
+
|
62
|
+
## Multiple folders, different log and more Handler in a daemon process
|
63
|
+
|
64
|
+
### Edit example.rb
|
65
|
+
|
66
|
+
require 'logfile_transfer'
|
67
|
+
|
68
|
+
class Test < LogfileTransfer::Handler
|
69
|
+
|
70
|
+
def init
|
71
|
+
@test_log_file = File.new '/tmp/test.log', 'a'
|
72
|
+
@test_log_file.sync = true
|
73
|
+
end
|
74
|
+
|
75
|
+
def handle log_path, log_fn, line, line_count, pattern
|
76
|
+
@test_log_file.puts "#{log_path}, #{log_fn}, #{line_count}, #{pattern}"
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
class Test1 < LogfileTransfer::Handler
|
82
|
+
|
83
|
+
def init
|
84
|
+
@test1_log_file = File.new '/tmp/test1.log', 'a'
|
85
|
+
@test1_log_file.sync = true
|
86
|
+
end
|
87
|
+
|
88
|
+
def handle log_path, log_fn, line, line_count, pattern
|
89
|
+
@test1_log_file.puts line
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
LogfileTransfer.run ARGV, 2001, File.expand_path(File.dirname(__FILE__))
|
95
|
+
|
96
|
+
### Edit config.yaml
|
97
|
+
|
98
|
+
---
|
99
|
+
- !ruby/object:LogfileTransfer::FileMonitorObj
|
100
|
+
absolute_path: /data/webroot/log
|
101
|
+
dir_disallow: []
|
102
|
+
file_disallow:
|
103
|
+
- .*
|
104
|
+
file_allow:
|
105
|
+
- \.log\.
|
106
|
+
patterns:
|
107
|
+
- - gamestart
|
108
|
+
- - !ruby/object:Test {}
|
109
|
+
- !ruby/object:Test1 {}
|
110
|
+
- - gamestop
|
111
|
+
- - !ruby/object:Test {}
|
112
|
+
- !ruby/object:Test1 {}
|
113
|
+
- !ruby/object:LogfileTransfer::FileMonitorObj
|
114
|
+
absolute_path: /data/webroot/tlog
|
115
|
+
dir_disallow: []
|
116
|
+
file_disallow:
|
117
|
+
- .*
|
118
|
+
file_allow:
|
119
|
+
- \.log\.
|
120
|
+
patterns:
|
121
|
+
- - gamestart
|
122
|
+
- - !ruby/object:Test {}
|
123
|
+
- !ruby/object:Test1 {}
|
data/example.rb
CHANGED
@@ -3,29 +3,32 @@
|
|
3
3
|
lib_dir = File.join File.dirname(__FILE__), 'lib'
|
4
4
|
$:.unshift lib_dir unless $:.include? lib_dir
|
5
5
|
|
6
|
-
require 'scribe'
|
7
6
|
require 'logfile_transfer.rb'
|
8
7
|
|
9
8
|
class Test < LogfileTransfer::Handler
|
9
|
+
|
10
10
|
def init
|
11
|
+
@test_log_file = File.new '/tmp/test.log', 'a'
|
12
|
+
@test_log_file.sync = true
|
11
13
|
end
|
14
|
+
|
12
15
|
def handle log_path, log_fn, line, line_count, pattern
|
13
|
-
|
14
|
-
puts '+++++++++++++++++++'
|
15
|
-
else
|
16
|
-
puts '-------------------'
|
17
|
-
end
|
18
|
-
puts "#{log_path}, #{log_fn}, #{line_count}, #{pattern}"
|
16
|
+
@test_log_file.puts "#{log_path}, #{log_fn}, #{line_count}, #{pattern}"
|
19
17
|
end
|
18
|
+
|
20
19
|
end
|
21
20
|
|
22
21
|
class Test1 < LogfileTransfer::Handler
|
22
|
+
|
23
23
|
def init
|
24
|
-
@
|
24
|
+
@test1_log_file = File.new '/tmp/test1.log', 'a'
|
25
|
+
@test1_log_file.sync = true
|
25
26
|
end
|
27
|
+
|
26
28
|
def handle log_path, log_fn, line, line_count, pattern
|
27
|
-
@
|
29
|
+
@test1_log_file.puts line
|
28
30
|
end
|
31
|
+
|
29
32
|
end
|
30
33
|
|
31
34
|
LogfileTransfer.run ARGV, 2001, File.expand_path(File.dirname(__FILE__))
|
data/lib/logfile_transfer.rb
CHANGED
@@ -156,6 +156,7 @@ module LogfileTransfer
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def self.daemon
|
159
|
+
@monitor_paths = []
|
159
160
|
YAML.load_file(@config_file_name).each do |obj|
|
160
161
|
log "absolute path: #{obj.absolute_path}"
|
161
162
|
log "dir disallow: #{obj.dir_disallow}"
|
@@ -169,6 +170,7 @@ module LogfileTransfer
|
|
169
170
|
end
|
170
171
|
end
|
171
172
|
|
173
|
+
@monitor_paths << obj.absolute_path
|
172
174
|
@threads << Thread.new do
|
173
175
|
begin
|
174
176
|
m = FileMonitor.new(obj.absolute_path)
|
@@ -221,14 +223,14 @@ module LogfileTransfer
|
|
221
223
|
client.puts(Prompt_exiting)
|
222
224
|
@exit_flag = true;
|
223
225
|
|
224
|
-
|
225
|
-
system "touch #{
|
226
|
+
@monitor_paths.each do |absolute_path|
|
227
|
+
system "touch #{absolute_path}/#{Stop_cmd_file_name}"
|
226
228
|
end
|
227
229
|
|
228
230
|
sleep 1
|
229
231
|
|
230
|
-
|
231
|
-
system "unlink #{
|
232
|
+
@monitor_paths.each do |absolute_path|
|
233
|
+
system "unlink #{absolute_path}/#{Stop_cmd_file_name}"
|
232
234
|
end
|
233
235
|
|
234
236
|
# puts 'client.close'
|
@@ -296,6 +298,7 @@ module LogfileTransfer
|
|
296
298
|
puts Prompt_starting
|
297
299
|
|
298
300
|
daemonize_app working_directory
|
301
|
+
|
299
302
|
@daemon_log_file_name = "#{working_directory}/#{@daemon_log_file_name}"
|
300
303
|
@daemon_log_file = File.new @daemon_log_file_name, 'a'
|
301
304
|
@daemon_log_file.sync = true
|