apache_log-parser 2.0.1 → 2.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d58c4fdaad1564bc136957c9c523f1033018c7b3
4
- data.tar.gz: ebe791bfd38e8197305e6facb1bebab6a910084e
3
+ metadata.gz: d7b3cf2d958865b1b7ed59532445be7468c0c4ea
4
+ data.tar.gz: eef9f4f04a09fc17ba7db8b075b7da6d59c4df0c
5
5
  SHA512:
6
- metadata.gz: 5daa56c8008103401cca6e2aad85278fec7f846425b18c9b7b1e1140e60069a454a83b7d90ea70393bc6a5dd1e0ccccf5007761d839f7c42630d9d7f9f5ac7a5
7
- data.tar.gz: ee9130d6a7cc7a20f5f773e6bf68202e08625fd637f5d763724cb548061f82b7e4ce5c73f8a447cc48b62cd519c7eb6e12fa1006e278313c8a46bc8f09a79172
6
+ metadata.gz: 1641a79197ca5cbf216dd02e5f81ce935bd3c2a3098093220bb5b63b01580d32b19304505c25c62b5167348636650380bbccf2aab272d27fa5c1438f383551bb
7
+ data.tar.gz: ba877b92b6dd6e1254be3bd788f62b7b38d207fb4123b4bac630d1e4ed916bb0909dffd52c5989ad93f792aa9ac6516fbe6704941c77421872b6b63417fe58ec
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
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
- common_log = ApacheLog::Parser.parse(log_line, 'combined')
32
- common_log[:referer] #=> referer
33
- common_log[:user_agent] #=> user_agent
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
- # custom format: LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%v\" \"%{cookie}n\" %D"
37
- common_log = ApacheLog::Parser.parse(log_line, 'combined', %w(vhost usertrack request_duration))
38
- common_log[:user_agent] #=> user_agent
39
- common_log[:vhost] #=> vhost
40
- common_log[:usertrack] #=> usertrack
41
- common_log[:request_duration] #=> request_duration
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'.
@@ -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
- match = pattern.match(line)
32
- raise "parse error\n at line: <#{line}> \n" if match.nil?
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
- columns = match.to_a
36
+ private
37
+ def self.generate_hash(keys, values)
38
+ hash = {}
35
39
 
36
- parsed_hash = {}
37
- fields.each.with_index do |val, idx|
38
- val = val.to_sym
39
- if val == :datetime
40
- parsed_hash[val] = to_datetime(columns[idx+1])
41
- elsif val == :request
42
- parsed_hash[val] = parse_request(columns[idx+1])
43
- else
44
- parsed_hash[val] = columns[idx+1]
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
- parsed_hash
49
- end
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
@@ -1,5 +1,5 @@
1
1
  module ApacheLog
2
2
  module Parser
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
5
5
  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.1
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-10 00:00:00.000000000 Z
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