loggie 0.0.4 → 0.0.5

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: 1f5379f3de4e3589a9e4932702b79244c6f26a1a
4
- data.tar.gz: a80e9996174e3a85fdfad3f5ac0aad08a3626404
3
+ metadata.gz: e31a124d2613c8265e77ced8b46e352287a03980
4
+ data.tar.gz: 48593347a0e3f34b251b178dc36f9471dfb05675
5
5
  SHA512:
6
- metadata.gz: 05f8aeb73e4ae741e9bb791bd32ccb602b54c0600ab0e0e743b28d3bebe98aad998532425ea0aac87071f7cb4edc00eadf64d16dd06514300470bed65ca254ee
7
- data.tar.gz: 1e97433ff0b40817b2eb9360be901018adb250019f4cd1ee89ff30e876506bbe0809aa1c5cdb43ccd377dc4e9aacd6ab1dfefac312481e90145f853ae9e5ba93
6
+ metadata.gz: 2e3a10a0b3b36f0a3ca530eab10e3fd052b25fc2e31a2d97e7223e2bc7d1e4ca6b1169177dc85e08aa2e0c27c546ab3c0044cba00aec65a62fd128cc9f52ee0c
7
+ data.tar.gz: 5e81feeb3d6d66c496f2e55422d4b8aeb4ca0840e21213eb49d4a7980c983379d5bd5ae9ec467a984e35cd5f67799158a34e8cef430aeaf8688ec7799887d88f
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Loggie
1
+ # Loggie [![CircleCI](https://circleci.com/gh/IanVaughan/loggie.svg?style=svg)](https://circleci.com/gh/IanVaughan/loggie) [![Gem Version](https://badge.fury.io/rb/loggie.svg)](https://badge.fury.io/rb/loggie)
2
2
 
3
3
  ## Installation
4
4
 
@@ -16,33 +16,9 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install loggie
18
18
 
19
- ## Usage
20
-
21
- ```ruby
22
- Loggie.search(query: "foobar")
23
- => {:timestamp=>Sun, 08 Jan 2017 01:00:58 +0000,
24
- :message=>
25
- { "remote_addr"=>"11.11.36.72",
26
- "version"=>"HTTP/1.1",
27
- "host"=>"host.com",
28
- "x_forwared_for"=>"11.11.11.11",
29
- ...
30
-
31
- ```
32
-
33
- Or, use from the command line with:
34
-
35
- `loggie foobar`
36
-
37
- env is required for command line usage, and can be prefixed to the command, eg:
38
-
39
- `READ_TOKEN=abc LOG_FILES=x,y,z loggie foobar`
40
-
41
- Or the create a `.loggie` file in the current path.
42
-
43
19
  ## Configuring Loggie
44
20
 
45
- ```
21
+ ```ruby
46
22
  Loggie.configure do |config|
47
23
  # from https://logentries.com/app/<app>#/user-account/apikey
48
24
  config.read_token = 'key'
@@ -66,6 +42,30 @@ Loggie.configure do |config|
66
42
  end
67
43
  ```
68
44
 
45
+ ## Usage
46
+
47
+ ```ruby
48
+ Loggie.search(query: "foobar") { |progress| puts "#{progress}% there!" }
49
+ => {:timestamp=>Sun, 08 Jan 2017 01:00:58 +0000,
50
+ :message=>
51
+ { "remote_addr"=>"11.11.36.72",
52
+ "version"=>"HTTP/1.1",
53
+ "host"=>"host.com",
54
+ "x_forwared_for"=>"11.11.11.11",
55
+ ...
56
+
57
+ ```
58
+
59
+ Or, use from the command line with:
60
+
61
+ `loggie foobar`
62
+
63
+ env is required for command line usage, and can be prefixed to the command, eg:
64
+
65
+ `READ_TOKEN=abc LOG_FILES=x,y,z loggie foobar`
66
+
67
+ Or the create a `.loggie` file somewhere in the current path.
68
+
69
69
  ## Development
70
70
 
71
71
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -13,7 +13,7 @@ require "loggie/logentries/retry"
13
13
  require "loggie/logentries/response"
14
14
 
15
15
  module Loggie
16
- def self.search(query:, from: 1.week.ago, to: Time.zone.now)
17
- Logentries::Search.new(query: query, from: from, to: to).call
16
+ def self.search(query:, from: 1.week.ago, to: Time.zone.now, &block)
17
+ Logentries::Search.new(query: query, from: from, to: to, block: block).call
18
18
  end
19
19
  end
@@ -20,7 +20,7 @@ module Loggie
20
20
 
21
21
  def initialize
22
22
  @max_retry = 50
23
- @log_level = :info
23
+ @log_level = :fatal
24
24
  @sleep_before_retry_seconds = 0.5
25
25
  @default_fields_included = [
26
26
  "request_method", "path_info", "query_string", "agent",
@@ -10,10 +10,13 @@ module Loggie
10
10
  class RetryCountExceededError < RetryError; end
11
11
  class RetryResponseError < RetryError; end
12
12
 
13
- def initialize
13
+ MIN_ACCEPTED_SUCCESS_STATUS_CODE = 203
14
+
15
+ def initialize(block: nil)
14
16
  @retry_count = 0
15
17
  @max_retry = Loggie.configuration.max_retry
16
18
  @sleep_before_retry_seconds = Loggie.configuration.sleep_before_retry_seconds
19
+ @user_block = block
17
20
  end
18
21
 
19
22
  def call(url, method, options, &block)
@@ -21,31 +24,32 @@ module Loggie
21
24
  response = block.call(url, method, options)
22
25
  logger.debug "#{self.class} retry:#{@retry_count}, response:#{response.body}"
23
26
 
24
- if response.code.to_i > 203
27
+ if response.code.to_i > MIN_ACCEPTED_SUCCESS_STATUS_CODE
25
28
  raise RetryCountExceededError, "Failed request with:#{response.message}"
26
29
  end
27
30
 
28
31
  res = Response.new response
29
32
  return res.events if res.events?
30
- logger.info "Logentries returned progress:#{res.progress}"
31
33
 
32
34
  @retry_count += 1
33
35
  if @retry_count > max_retry
34
36
  raise RetryCountExceededError, "Retry count of #{max_retry} reached"
35
37
  end
38
+ logger.debug "Logentries returned progress:#{res.progress}, retry_count:#{@retry_count}"
39
+ user_block.call(res.progress, @retry_count) if user_block
36
40
 
37
41
  sleep sleep_before_retry_seconds
38
42
 
39
43
  self.call(res.next_url, :get, nil, &block)
40
44
 
41
45
  rescue RetryError => e
42
- logger.error e.message
43
- nil
46
+ logger.info e.message
47
+ []
44
48
  end
45
49
 
46
50
  private
47
51
 
48
- attr_reader :max_retry, :sleep_before_retry_seconds
52
+ attr_reader :max_retry, :sleep_before_retry_seconds, :user_block
49
53
  end
50
54
  end
51
55
  end
@@ -12,11 +12,11 @@ module Loggie
12
12
  # @param [DateTime] to: query to date
13
13
  # @param [Array] log_files: list of log id files to search. default ENV['LOG_FILES']
14
14
  #
15
- def initialize(query: nil, from: nil, to: nil, log_files: nil)
15
+ def initialize(query: nil, from: nil, to: nil, log_files: nil, block: nil)
16
16
  @query, @from, @to = query, from, to
17
17
  @log_files = log_files || Loggie.configuration.log_files
18
18
  @extract = Extract.new
19
- @request = Request.new(retry_mechanism: Retry.new)
19
+ @request = Request.new(retry_mechanism: Retry.new(block: block))
20
20
  end
21
21
 
22
22
  def call(query: nil, from: nil, to: nil, log_files: nil)
@@ -1,3 +1,3 @@
1
1
  module Loggie
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Vaughan
@@ -133,7 +133,6 @@ files:
133
133
  - ".gitignore"
134
134
  - ".rspec"
135
135
  - ".ruby-version"
136
- - ".travis.yml"
137
136
  - Gemfile
138
137
  - LICENSE.txt
139
138
  - README.md
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.2.0
5
- before_install: gem install bundler -v 1.12.5