ktlacaelel-plog 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +20 -4
- data/VERSION +1 -1
- data/bin/plog +1 -1
- data/lib/cli.rb +30 -22
- data/lib/completed_line.rb +0 -1
- data/lib/log_file.rb +15 -9
- data/plog.gemspec +1 -1
- data/test/log_file_test.rb +9 -6
- metadata +2 -3
data/README.rdoc
CHANGED
@@ -1,13 +1,27 @@
|
|
1
|
-
=
|
1
|
+
= Plog
|
2
|
+
|
3
|
+
Ruby on Rails *Production-Log* statistics generator.
|
4
|
+
by Kazuyoshi Tlacaelel.
|
5
|
+
|
6
|
+
== Usage:
|
7
|
+
|
8
|
+
HELP?
|
9
|
+
The "plog" ( production log ) executable receives one option.
|
10
|
+
This must be a directory containing one or more production logs.
|
11
|
+
Only logs in the first level will be parsed.
|
12
|
+
Recursive reading is not allowed
|
13
|
+
|
14
|
+
USAGE:
|
15
|
+
$ plog directory_with_logs/
|
2
16
|
|
3
|
-
Description goes here.
|
4
17
|
|
5
18
|
== Note on Patches/Pull Requests
|
6
|
-
|
19
|
+
|
20
|
+
* Send me a brief message
|
7
21
|
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
22
|
* Add tests for it. This is important so I don't break it in a
|
10
23
|
future version unintentionally.
|
24
|
+
* Make your feature addition or bug fix.
|
11
25
|
* Commit, do not mess with rakefile, version, or history.
|
12
26
|
(if you want to have your own version, that is fine but
|
13
27
|
bump version in a commit by itself I can ignore when I pull)
|
@@ -16,3 +30,5 @@ Description goes here.
|
|
16
30
|
== Copyright
|
17
31
|
|
18
32
|
Copyright (c) 2009 Kazuyoshi Tlacaelel. See LICENSE for details.
|
33
|
+
|
34
|
+
The end.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/plog
CHANGED
data/lib/cli.rb
CHANGED
@@ -2,19 +2,20 @@ module Plog
|
|
2
2
|
|
3
3
|
class Cli
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :source_directory, :log_files
|
6
6
|
|
7
|
-
LOG_FILE = '
|
7
|
+
LOG_FILE = 'statistics.txt'
|
8
8
|
|
9
9
|
# ==========================================================================
|
10
10
|
# CLIENT INTERFACE
|
11
11
|
# ==========================================================================
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@directory = directory
|
13
|
+
def initialize(source_directory, target_directory)
|
15
14
|
@log_files = []
|
16
|
-
|
17
|
-
|
15
|
+
@source_directory = source_directory
|
16
|
+
@target_directory = target_directory
|
17
|
+
check_directory_consistency!
|
18
|
+
preload_log_files!
|
18
19
|
end
|
19
20
|
|
20
21
|
def run!
|
@@ -45,37 +46,46 @@ module Plog
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def parse_object_files
|
48
|
-
Dir.glob(
|
49
|
-
file = File.new(
|
49
|
+
Dir.glob(object_file_pattern).each do |object_file|
|
50
|
+
file = File.new(statistic_file_path, 'a+')
|
50
51
|
file.puts trim(ObjectFile.new(object_file).export)
|
51
52
|
file.close
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
56
|
+
def object_file_pattern
|
57
|
+
File.join(@target_directory, 'objects') + '/*'
|
58
|
+
end
|
59
|
+
|
60
|
+
def statistic_file_path
|
61
|
+
File.join(@target_directory, LOG_FILE)
|
62
|
+
end
|
63
|
+
|
55
64
|
def destroy_old_log_file
|
56
|
-
FileUtils.touch
|
57
|
-
FileUtils.rm
|
65
|
+
FileUtils.touch statistic_file_path
|
66
|
+
FileUtils.rm statistic_file_path
|
58
67
|
end
|
59
68
|
|
60
69
|
def append_headers_to_log_file
|
61
|
-
file = File.new(
|
70
|
+
file = File.new(statistic_file_path, 'a+')
|
62
71
|
file.puts trim(ObjectFile.formated_headers)
|
63
72
|
file.close
|
64
73
|
end
|
65
74
|
|
66
|
-
def
|
67
|
-
abort directory_not_found_banner unless File.exist? @
|
75
|
+
def check_directory_consistency!
|
76
|
+
abort directory_not_found_banner unless File.exist? @source_directory
|
68
77
|
end
|
69
78
|
|
70
|
-
def
|
71
|
-
Dir.glob(File.join(@
|
72
|
-
@
|
79
|
+
def preload_log_files!
|
80
|
+
Dir.glob(File.join(@source_directory, '*.log')).each do |log_file|
|
81
|
+
puts @target_directory
|
82
|
+
@log_files << LogFile.new(log_file, @target_directory)
|
73
83
|
stdout loading_log_file_banner(log_file)
|
74
84
|
end
|
75
85
|
end
|
76
86
|
|
77
87
|
def stdout(string)
|
78
|
-
puts '
|
88
|
+
puts ' ---> ' + string
|
79
89
|
end
|
80
90
|
|
81
91
|
# ==========================================================================
|
@@ -83,10 +93,8 @@ module Plog
|
|
83
93
|
# ==========================================================================
|
84
94
|
|
85
95
|
def notice_banner
|
86
|
-
'
|
87
|
-
|
88
|
-
|
89
|
-
Parsing logs, this may take a logn-while go get yourself a coffe!
|
96
|
+
'Parsing logs...
|
97
|
+
This may take a long-while, go get yourself a coffee!
|
90
98
|
While I hanlde this stuff for you.
|
91
99
|
'
|
92
100
|
end
|
@@ -104,7 +112,7 @@ module Plog
|
|
104
112
|
end
|
105
113
|
|
106
114
|
def directory_not_found_banner
|
107
|
-
'No such dir: %s' % @
|
115
|
+
'No such dir: %s' % @source_directory
|
108
116
|
end
|
109
117
|
|
110
118
|
end
|
data/lib/completed_line.rb
CHANGED
data/lib/log_file.rb
CHANGED
@@ -2,18 +2,21 @@ module Plog
|
|
2
2
|
|
3
3
|
class LogFile < File
|
4
4
|
|
5
|
-
DUMP_DIR = 'objects'
|
6
|
-
|
7
5
|
attr_accessor :name
|
8
6
|
|
9
|
-
def initialize(file)
|
10
|
-
|
11
|
-
|
12
|
-
end
|
7
|
+
def initialize(file, dump_dir)
|
8
|
+
@dump_dir = dump_dir
|
9
|
+
check_dump_dir_consistency!
|
13
10
|
super(file, 'r')
|
14
11
|
@name = file
|
15
12
|
end
|
16
13
|
|
14
|
+
def check_dump_dir_consistency!
|
15
|
+
unless File.exist? objects_recipient_path
|
16
|
+
FileUtils.mkdir_p objects_recipient_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
17
20
|
def validate(file)
|
18
21
|
abort 'File not found: ' + file.inspect unless File.exist? file
|
19
22
|
end
|
@@ -21,12 +24,11 @@ module Plog
|
|
21
24
|
def parse_completed_lines!
|
22
25
|
each_line do |line|
|
23
26
|
CompletedLine.read! line
|
24
|
-
parse_completed_line
|
27
|
+
parse_completed_line if CompletedLine.valid?
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
31
|
def parse_completed_line
|
29
|
-
return unless CompletedLine.valid?
|
30
32
|
of = ObjectFile.new(object_path, 'w+')
|
31
33
|
of.simplified_url = CompletedLine.url.simplify
|
32
34
|
of.append_total_time CompletedLine.total_time
|
@@ -38,7 +40,11 @@ module Plog
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def object_path
|
41
|
-
File.join(
|
43
|
+
File.join(objects_recipient_path, CompletedLine.url.hashify)
|
44
|
+
end
|
45
|
+
|
46
|
+
def objects_recipient_path
|
47
|
+
@objects_recipient_path ||= File.join(@dump_dir, 'objects')
|
42
48
|
end
|
43
49
|
|
44
50
|
end
|
data/plog.gemspec
CHANGED
data/test/log_file_test.rb
CHANGED
@@ -4,11 +4,13 @@ class LogFileTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
@log_file = 'test/data/example.log'
|
7
|
-
@
|
7
|
+
@dump_dir = 'plog'
|
8
|
+
@file = Plog::LogFile.new(@log_file, @dump_dir)
|
8
9
|
@object_hash = 'a1e0e00d04e82bdf0f1ac151de03591c'
|
9
|
-
@
|
10
|
+
@subdir = 'plog/objects'
|
11
|
+
@object_path = @subdir + '/' + @object_hash
|
10
12
|
@final_csv_result = '10,70,40,30,/users/[0-9]'
|
11
|
-
@default_object_path = 'objects/2a5565416b0c92c6c5081342322bf945'
|
13
|
+
@default_object_path = 'plog/objects/2a5565416b0c92c6c5081342322bf945'
|
12
14
|
end
|
13
15
|
|
14
16
|
def teardown
|
@@ -17,18 +19,19 @@ class LogFileTest < Test::Unit::TestCase
|
|
17
19
|
|
18
20
|
should 'generate an appropriate object_path' do
|
19
21
|
assert_equal @default_object_path, @file.object_path
|
22
|
+
assert_equal @subdir, @file.objects_recipient_path
|
20
23
|
end
|
21
24
|
|
22
25
|
def whipe_out_objects_dir
|
23
|
-
Dir.glob('./objects/*').each do |file|
|
26
|
+
Dir.glob('./plog/objects/*').each do |file|
|
24
27
|
FileUtils.rm_r(file, :force => true)
|
25
28
|
end
|
26
|
-
FileUtils.rmdir './objects'
|
29
|
+
FileUtils.rmdir './plog/objects'
|
27
30
|
end
|
28
31
|
|
29
32
|
should 'parse data appropriately' do
|
30
33
|
whipe_out_objects_dir
|
31
|
-
@file = Plog::LogFile.new(@log_file)
|
34
|
+
@file = Plog::LogFile.new(@log_file, @dump_dir)
|
32
35
|
@file.parse_completed_lines!
|
33
36
|
assert_equal @final_csv_result, File.new(@object_path).read.chomp
|
34
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ktlacaelel-plog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyoshi Tlacaelel
|
@@ -55,7 +55,6 @@ files:
|
|
55
55
|
- test/url_test.rb
|
56
56
|
has_rdoc: false
|
57
57
|
homepage: http://github.com/ktlacaelel/plog
|
58
|
-
licenses:
|
59
58
|
post_install_message:
|
60
59
|
rdoc_options:
|
61
60
|
- --charset=UTF-8
|
@@ -76,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
75
|
requirements: []
|
77
76
|
|
78
77
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.2.0
|
80
79
|
signing_key:
|
81
80
|
specification_version: 3
|
82
81
|
summary: Plog - Ruby on Rails production log statistic generator. by Kazuyoshi Tlacaelel
|