apache_log-parser 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +10 -10
- data/lib/apache_log/parser.rb +20 -17
- data/lib/apache_log/parser/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7b3cf2d958865b1b7ed59532445be7468c0c4ea
|
4
|
+
data.tar.gz: eef9f4f04a09fc17ba7db8b075b7da6d59c4df0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1641a79197ca5cbf216dd02e5f81ce935bd3c2a3098093220bb5b63b01580d32b19304505c25c62b5167348636650380bbccf2aab272d27fa5c1438f383551bb
|
7
|
+
data.tar.gz: ba877b92b6dd6e1254be3bd788f62b7b38d207fb4123b4bac630d1e4ed916bb0909dffd52c5989ad93f792aa9ac6516fbe6704941c77421872b6b63417fe58ec
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ApacheLog::Parser
|
2
|
-
|
2
|
+
[![Build Status](https://travis-ci.org/takady/apache_log-parser.svg?branch=master)](https://travis-ci.org/takady/apache_log-parser) [![Code Climate](https://codeclimate.com/github/takady/apache_log-parser/badges/gpa.svg)](https://codeclimate.com/github/takady/apache_log-parser)
|
3
3
|
Gem to parse apache log including common, combined and customized format.
|
4
4
|
|
5
5
|
## Installation
|
@@ -28,17 +28,17 @@ common_log[:datetime] #=> datetime
|
|
28
28
|
common_log[:request] #=> request
|
29
29
|
|
30
30
|
# combined format
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
combined_log = ApacheLog::Parser.parse(log_line, 'combined')
|
32
|
+
combined_log[:referer] #=> referer
|
33
|
+
combined_log[:user_agent] #=> user_agent
|
34
34
|
|
35
35
|
# custom format(additional fields after 'combined')
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
# e.g. "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%v\" \"%{cookie}n\" %D"
|
37
|
+
custom_log = ApacheLog::Parser.parse(log_line, 'combined', %w(vhost usertrack request_duration))
|
38
|
+
custom_log[:user_agent] #=> user_agent
|
39
|
+
custom_log[:vhost] #=> vhost
|
40
|
+
custom_log[:usertrack] #=> usertrack
|
41
|
+
custom_log[:request_duration] #=> request_duration
|
42
42
|
```
|
43
43
|
|
44
44
|
The format parameter must be 'common' or 'combined'.
|
data/lib/apache_log/parser.rb
CHANGED
@@ -5,7 +5,6 @@ module ApacheLog
|
|
5
5
|
module Parser
|
6
6
|
|
7
7
|
def self.parse(line, format, additional_fields=[])
|
8
|
-
|
9
8
|
common_fields = %w(remote_host identity_check user datetime request status size)
|
10
9
|
combined_fields = common_fields + %w(referer user_agent)
|
11
10
|
|
@@ -28,27 +27,31 @@ module ApacheLog
|
|
28
27
|
raise "format error\n no such format: <#{format}> \n"
|
29
28
|
end
|
30
29
|
|
31
|
-
|
32
|
-
raise "parse error\n at line: <#{line}> \n" if
|
30
|
+
matched = pattern.match(line)
|
31
|
+
raise "parse error\n at line: <#{line}> \n" if matched.nil?
|
32
|
+
|
33
|
+
generate_hash(fields, matched.to_a)
|
34
|
+
end
|
33
35
|
|
34
|
-
|
36
|
+
private
|
37
|
+
def self.generate_hash(keys, values)
|
38
|
+
hash = {}
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
keys.each.with_index do |key, idx|
|
41
|
+
key = key.to_sym
|
42
|
+
case key
|
43
|
+
when :datetime
|
44
|
+
hash[key] = to_datetime(values[idx+1])
|
45
|
+
when :request
|
46
|
+
hash[key] = parse_request(values[idx+1])
|
47
|
+
else
|
48
|
+
hash[key] = values[idx+1]
|
49
|
+
end
|
45
50
|
end
|
46
|
-
end
|
47
51
|
|
48
|
-
|
49
|
-
|
52
|
+
hash
|
53
|
+
end
|
50
54
|
|
51
|
-
private
|
52
55
|
def self.to_datetime(str)
|
53
56
|
DateTime.strptime( str, '%d/%b/%Y:%T %z')
|
54
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apache_log-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuichi Takada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|