ghost_reader 1.1.5 → 1.1.6

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.
@@ -21,12 +21,12 @@ module GhostReader
21
21
  config.service[:logger] ||= config.logger
22
22
  config.client ||= Client.new(config.service)
23
23
  unless config.no_auto_spawn
24
- config.logger.debug "GhostReader spawning agents."
24
+ log "GhostReader spawning agents."
25
25
  spawn_retriever
26
26
  spawn_reporter
27
- config.logger.debug "GhostReader spawned its agents."
27
+ log "GhostReader spawned its agents."
28
28
  end
29
- config.logger.info "Initialized GhostReader backend."
29
+ log "Initialized GhostReader backend.", :info
30
30
  end
31
31
 
32
32
  def available_locales
@@ -38,13 +38,13 @@ module GhostReader
38
38
  # this won't be called if memoize kicks in
39
39
  def lookup(locale, key, scope = [], options = {})
40
40
  raise 'no fallback given' if config.fallback.nil?
41
- config.logger.debug "lookup: #{locale} #{key} #{scope.inspect} #{options.inspect}"
41
+ log "lookup: #{locale} #{key} #{scope.inspect} #{options.inspect}"
42
42
 
43
43
  result = config.fallback.translate(locale, key, options)
44
- config.logger.debug "fallback result: #{result.inspect}"
44
+ log "fallback result: #{result.inspect}"
45
45
  return result
46
46
  rescue Exception => ex
47
- config.logger.debug "fallback.translate raised exception: #{ex}"
47
+ log "fallback.translate raised exception: #{ex}"
48
48
  ensure # make sure everything is tracked
49
49
  # TODO results which are hashes need to be tracked disaggregated
50
50
  track({ key => { locale.to_s => { 'default' => result } } }) unless result.is_a?(Hash)
@@ -53,9 +53,9 @@ module GhostReader
53
53
 
54
54
  def track(missing)
55
55
  return if missings.nil? # not yet initialized
56
- config.logger.debug "[#{$$}] tracking: #{missing.inspect}"
56
+ log "tracking: #{missing.inspect}"
57
57
  self.missings.deep_merge!(missing)
58
- config.logger.debug "[#{$$}] missings: #{missings.inspect}"
58
+ log "missings: #{missings.inspect}"
59
59
  end
60
60
 
61
61
  # data, e.g. {'en' => {'this' => {'is' => {'a' => {'test' => 'This is a test.'}}}}}
@@ -67,60 +67,59 @@ module GhostReader
67
67
 
68
68
  # performs initial and incremental requests
69
69
  def spawn_retriever
70
- config.logger.debug "Spawning retriever."
70
+ log "Spawning retriever."
71
71
  @retriever = Thread.new do
72
72
  begin
73
- config.logger.debug "Performing initial request."
73
+ log "Performing initial request."
74
74
  response = config.client.initial_request
75
75
  memoize_merge! response[:data]
76
76
  self.missings = {} # initialized
77
- config.logger.info "Initial request successfull."
77
+ log "Initial request successfull.", :info
78
78
  until false
79
79
  begin
80
80
  sleep config.retrieval_interval
81
81
  response = config.client.incremental_request
82
82
  if response[:status] == 200
83
- config.logger.info "Incremental request with data."
84
- config.logger.debug "Data: #{response[:data].inspect}"
83
+ log "Incremental request with data.", :info
84
+ log "Data: #{response[:data].inspect}"
85
85
  memoize_merge! response[:data], :method => :deep_merge!
86
86
  else
87
- config.logger.debug "Incremental request, but no data."
87
+ log "Incremental request, but no data."
88
88
  end
89
89
  rescue => ex
90
- config.logger.error "Exception in retriever loop: #{ex}"
91
- config.logger.debug ex.backtrace.join("\n")
90
+ log "Exception in retriever loop: #{ex}", :error
91
+ log ex.backtrace.join("\n")
92
92
  end
93
93
  end
94
94
  rescue => ex
95
- config.logger.error "Exception in retriever thread: #{ex}"
96
- config.logger.debug ex.backtrace.join("\n")
95
+ log "Exception in retriever thread: #{ex}", :error
96
+ log ex.backtrace.join("\n")
97
97
  end
98
98
  end
99
99
  end
100
100
 
101
101
  # performs reporting requests
102
102
  def spawn_reporter
103
- config.logger.debug "Spawning reporter."
103
+ log "Spawning reporter."
104
104
  @reporter = Thread.new do
105
105
  until false
106
106
  begin
107
107
  sleep config.report_interval
108
108
  unless self.missings.nil?
109
109
  unless self.missings.empty?
110
- config.logger.info "[#{$$}] Reporting request with % missings." %
111
- self.missings.keys.size
110
+ log "Reporting request with % missings." % self.missings.keys.size, :info
112
111
  config.client.reporting_request(missings)
113
112
  missings.clear
114
113
  else
115
- config.logger.debug "[#{$$}] Reporting request omitted, nothing to report."
114
+ log "Reporting request omitted, nothing to report."
116
115
  end
117
116
  else
118
- config.logger.debug "Reporting request omitted, not yet initialized," +
117
+ log "Reporting request omitted, not yet initialized," +
119
118
  " waiting for intial request."
120
119
  end
121
120
  rescue => ex
122
- config.logger.error "Exception in reporter thread: #{ex}"
123
- config.logger.debug ex.backtrace.join("\n")
121
+ log "Exception in reporter thread: #{ex}", :error
122
+ log ex.backtrace.join("\n")
124
123
  end
125
124
  end
126
125
  end
@@ -133,7 +132,7 @@ module GhostReader
133
132
  key, value = key_value
134
133
  result.merge key => flatten_translations(key, value, true, false)
135
134
  rescue ArgumentError => ae
136
- config.logger.error "Error: #{ae}"
135
+ log "Error: #{ae}", :error
137
136
  result
138
137
  end
139
138
  end
@@ -157,6 +156,11 @@ module GhostReader
157
156
  :service => {} # nested hash, see GhostReader::Client#default_config
158
157
  }
159
158
  end
159
+
160
+ def log(msg, level=:debug)
161
+ config.logger.send(level, "[#{$$}] #{msg}")
162
+ end
163
+
160
164
  end
161
165
 
162
166
  include I18n::Backend::Base
@@ -1,3 +1,3 @@
1
1
  module GhostReader
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghost_reader
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 5
10
- version: 1.1.5
9
+ - 6
10
+ version: 1.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phil Hofmann