betterlog 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 975990d950f8eb2ee21cfbbf52fa8472f8a706a02a01728e76e40005ca5807d3
4
- data.tar.gz: 74ec7d2ce187050e66d4ff5c424daffb99a18759e987a66a7340ec5edcdf16c1
3
+ metadata.gz: 4765c4c4583c00e53272425f3eba50890c1c1c9534bbcf0b9653befe1f5d59d0
4
+ data.tar.gz: 78523987e0a140b50aaee1e6d663b4c3821d5fab4e2dc750c17f5d3b5ca5b7d9
5
5
  SHA512:
6
- metadata.gz: f38d883bf8935c90af49649ed0627b2dc600cb992d03d746be12586cca817efb04820b55455b4f209f405edf1dee8400a950f7a283fa1019719d71d629f48f9c
7
- data.tar.gz: 1ac776bcbed6cafb804e25a6a1e4d41836bb232ef9b70b04d09fc6c6a80010c2bd187a88f3167495f2bff4fcd6fad34f55bada5e4e13801ed8dd5c3e2d1c505f
6
+ metadata.gz: 4cfd4bad70799e9e750439231bcc638e652f91e239f287688cab3895c0a6f72d143b48bb26297867860f1146c8837d1bdca595bd1a18bf601e24f467b869ddda
7
+ data.tar.gz: 76d29b2dd078b6ff14304851d2e62283434217d43667e62bad1b0f507ca729575b8927bdbd0d4e0264af377decf095377563fe6edd6660c287e1c4206a135405
data/README.md CHANGED
@@ -2,17 +2,58 @@
2
2
 
3
3
  ## Description
4
4
 
5
- Logging tools for betterplace structured logging
5
+ Logging tools for betterplace structured logging in rails applications.
6
+
7
+ ## Configuration
8
+
9
+ Copy the example configuration in config/log.yml into your application to get
10
+ you started. Then add this line to your Gemfile:
11
+
12
+ ```
13
+ gem 'betterlog'
14
+ ```
6
15
 
7
16
  ## Usage
8
17
 
9
18
  ### `betterlog`
10
19
 
11
- TODO
20
+ Use it to tail local logfiles:
21
+
22
+ ```
23
+ $ betterlog -f
24
+ ```
25
+
26
+ or filter from stdin with
27
+
28
+ ```
29
+ $ cat log/development.log | betterlog
30
+ ```
31
+
32
+ Search for GET in the last 1000 rails log lines:
33
+
34
+ ```
35
+ $ betterlog -F rails -n 1000 -s GET
36
+ ```
37
+
38
+ Display the help for more options with `betterlog -h`.
12
39
 
13
40
  ### `betterlog_pusher`
14
41
 
15
- TODO
42
+ - `BETTERLOG_SERVER_URL` is the URL log information is ultimately posted to
43
+ in the form of `https://user:password@appname-prd-log.betterops.de/log`.
44
+
45
+ - `BETTERLOG_LINES`, e. g. 1000, is the number of lines which are posted per
46
+ every request to the above URL.
47
+
48
+ - `REDIS_URL` the redis server URL for the server where Log information is
49
+ stored before posted to the betterlog server.
50
+
51
+ The rails application should be configured like this to store log information
52
+ on this redis server:
53
+
54
+ ```
55
+ config.logger = Betterlog::Logger.new(Redis.new(url: ENV.fetch('REDIS_URL')))
56
+ ```
16
57
 
17
58
  ### `betterlog_sink`
18
59
 
@@ -23,12 +64,12 @@ To tail a log and prettify the output just call and pipe to the `betterlog`
23
64
  executable:
24
65
 
25
66
  ```
26
- $ betterlog_sink --since=1m -f | betterlog
67
+ $ betterlog_sink --since=1m -f | betterlog
27
68
  ```
28
69
 
29
70
  The sink always defaults to the production logfile, to switch the context to
30
71
  staging, prepend the command with the `LOG_ENV` env variable like so:
31
72
 
32
73
  ```
33
- $ LOG_ENV=staging betterlog_sink -f | betterlog
74
+ $ LOG_ENV=staging betterlog_sink -f | betterlog
34
75
  ```
data/Rakefile CHANGED
@@ -24,6 +24,7 @@ GemHadar do
24
24
  dependency 'json', '~>2.0'
25
25
  dependency 'term-ansicolor', '~>1.3'
26
26
  dependency 'redis', '>=2.4'
27
+ dependency 'redlock'
27
28
  dependency 'excon'
28
29
 
29
30
  development_dependency 'rake'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/betterlog.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.3.0 ruby lib
2
+ # stub: betterlog 0.4.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.3.0"
6
+ s.version = "0.4.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["betterplace Developers".freeze]
11
- s.date = "2019-07-15"
11
+ s.date = "2019-07-17"
12
12
  s.description = "This library provides structure json logging for our rails projects".freeze
13
13
  s.email = "developers@betterplace.org".freeze
14
14
  s.executables = ["betterlog".freeze, "betterlog_pusher".freeze, "betterlog_sink".freeze]
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0"])
35
35
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
36
36
  s.add_runtime_dependency(%q<redis>.freeze, [">= 2.4"])
37
+ s.add_runtime_dependency(%q<redlock>.freeze, [">= 0"])
37
38
  s.add_runtime_dependency(%q<excon>.freeze, [">= 0"])
38
39
  else
39
40
  s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.10.0"])
@@ -46,6 +47,7 @@ Gem::Specification.new do |s|
46
47
  s.add_dependency(%q<json>.freeze, ["~> 2.0"])
47
48
  s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
48
49
  s.add_dependency(%q<redis>.freeze, [">= 2.4"])
50
+ s.add_dependency(%q<redlock>.freeze, [">= 0"])
49
51
  s.add_dependency(%q<excon>.freeze, [">= 0"])
50
52
  end
51
53
  else
@@ -59,6 +61,7 @@ Gem::Specification.new do |s|
59
61
  s.add_dependency(%q<json>.freeze, ["~> 2.0"])
60
62
  s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
61
63
  s.add_dependency(%q<redis>.freeze, [">= 2.4"])
64
+ s.add_dependency(%q<redlock>.freeze, [">= 0"])
62
65
  s.add_dependency(%q<excon>.freeze, [">= 0"])
63
66
  end
64
67
  end
data/bin/betterlog_pusher CHANGED
@@ -3,26 +3,32 @@
3
3
 
4
4
  require 'betterlog'
5
5
  require 'excon'
6
+ require 'redlock'
6
7
 
7
- lines = Integer(ENV.fetch('BETTERLOG_LINES', 1_000))
8
- url = ENV.fetch('BETTERLOG_SERVER_URL')
9
- name = ENV['BETTERLOG_NAME']
10
- redis = Redis.new(url: ENV.fetch('REDIS_URL'))
11
- logger = Betterlog::Logger.new(redis, name: name)
8
+ lines = Integer(ENV.fetch('BETTERLOG_LINES', 1_000))
9
+ lock_time = Integer(ENV.fetch('BETTERLOG_LOCK_TIME', 60_000))
10
+ url = ENV.fetch('BETTERLOG_SERVER_URL')
11
+ name = ENV['BETTERLOG_NAME']
12
+ redis_url = ENV.fetch('REDIS_URL')
13
+ redis = Redis.new(url: redis_url)
14
+ lm = Redlock::Client.new([ redis_url ])
15
+ logger = Betterlog::Logger.new(redis, name: name)
12
16
 
13
17
  quit = false
14
-
15
18
  [ :TERM, :INT, :QUIT ].each { |s| trap(s) { quit = true } }
16
19
 
17
20
  STDOUT.sync = true
18
21
  loop do
19
22
  count = 0
20
- logger.each_slice(lines).with_index do |batch, i|
21
- count.zero? and print ?(
22
- count += batch.sum(&:size)
23
- attempt(attempts: 10, sleep: -60, reraise: true) do
24
- print ?┄
25
- Excon.post(url, body: batch.join)
23
+ lm.lock!(File.basename($0), lock_time) do
24
+ print ?…
25
+ logger.each_slice(lines).with_index do |batch, i|
26
+ count.zero? and print ?(
27
+ count += batch.sum(&:size)
28
+ attempt(attempts: 10, sleep: -60, reraise: true) do
29
+ print ?┄
30
+ Excon.post(url, body: batch.join)
31
+ end
26
32
  end
27
33
  end
28
34
  quit and exit
@@ -31,4 +37,7 @@ loop do
31
37
  else
32
38
  print "→%s)" % Tins::Unit.format(count, format: '%.2f %U', prefix: 1024, unit: ?b)
33
39
  end
40
+ rescue Redlock::LockError => e
41
+ STDERR.puts "Caught #{e.class}: #{e} => Retrying!"
42
+ exit
34
43
  end
data/config/log.yml CHANGED
@@ -13,6 +13,7 @@ development: &development
13
13
  default: &default_format >
14
14
  {%lt%timestamp} {%5s%severity}
15
15
  "{%0.<%= ENV.fetch('COLUMNS', 80).to_i / 2 %>%message}"
16
+ {host}
16
17
  {location}
17
18
  {file}{-%O%backtrace}{-%O%meta}
18
19
  d: *default_format
@@ -23,6 +24,7 @@ development: &development
23
24
  metric: {metric} {value} {type}
24
25
  error_class: {error_class}
25
26
  backtrace: {%O%backtrace}
27
+ host: {host}
26
28
  location: {location}
27
29
  file: {file}
28
30
  meta: {%O%meta}\n
@@ -43,5 +45,21 @@ development: &development
43
45
  - /usr/local/var/log/elasticsearch.log
44
46
  legacy_supported: yes
45
47
  test: *development
46
- staging: *development
47
- production: *development
48
+ staging:
49
+ <<: *development
50
+ sink:
51
+ namespace: betterlog
52
+ source: betterlog-app
53
+ cluster:
54
+ name: betterlog
55
+ zone: europe-west1-b
56
+ project: project-42
57
+ production:
58
+ <<: *development
59
+ sink:
60
+ namespace: betterlog
61
+ source: betterlog-app
62
+ cluster:
63
+ name: betterlog
64
+ zone: europe-west1-b
65
+ project: project-666
data/lib/betterlog/log.rb CHANGED
@@ -113,7 +113,7 @@ module Betterlog
113
113
  rescue => error
114
114
  e = Log::Event.ify(error)
115
115
  rest |= e.as_hash.subhash(:error_class, :backtrace, :message)
116
- rest[:message] = "#{rest[:message]} while measuring metric #{metric}"
116
+ rest[:message] = "#{rest[:message].inspect} while measuring metric #{metric}"
117
117
  raise error
118
118
  ensure
119
119
  protect do
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -154,7 +154,7 @@ describe Betterlog::Log do
154
154
 
155
155
  class MyEx < StandardError
156
156
  def backtrace
157
- []
157
+ %w[ backtrace ]
158
158
  end
159
159
  end
160
160
 
@@ -162,18 +162,19 @@ describe Betterlog::Log do
162
162
  expected_event = Log::Event.new(
163
163
  metric: 'foo',
164
164
  type: 'seconds',
165
- value: 10.0,
166
- timestamp: "2011-11-11T10:11:21.000Z",
167
- message: 'MyEx: we were fucked while measuring metric foo',
165
+ value: 3.0,
166
+ timestamp: "2011-11-11T10:11:14.000Z",
167
+ message: '"MyEx: we were fucked" while measuring metric foo',
168
168
  error_class: 'MyEx',
169
- backtrace: [],
169
+ backtrace: %w[ backtrace ]
170
170
  )
171
171
  expect(instance).to receive(:emit).with(expected_event)
172
172
  raised = false
173
173
  begin
174
174
  Log.measure(metric: 'foo') do
175
- Time.dummy = Time.now + 10
175
+ Time.dummy = Time.now + 3
176
176
  raise MyEx, "we were fucked"
177
+ Time.dummy = Time.now + 7
177
178
  end
178
179
  rescue MyEx
179
180
  raised = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-15 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -156,6 +156,20 @@ dependencies:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
158
  version: '2.4'
159
+ - !ruby/object:Gem::Dependency
160
+ name: redlock
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
159
173
  - !ruby/object:Gem::Dependency
160
174
  name: excon
161
175
  requirement: !ruby/object:Gem::Requirement