betterlog 0.20.3 → 1.1.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: 1b03ee4885ecd0c19dadca8b79729aceae4910400fc8565385957b397838f743
4
- data.tar.gz: fd30dde7ce4900e0827078903413425bb065073827a810cc4b7d7da6ec02ef53
3
+ metadata.gz: dfdf595cf7daec3b80c23beccd01ef848e25e2c02d90d5b0c3b8599b380501e3
4
+ data.tar.gz: 6854574b6f78fed6ed4654ffb406190b22ecf11f8b1c0ec99cc82622b678a42f
5
5
  SHA512:
6
- metadata.gz: 5998de5d4c82cd9d2c4072d4a858704d4573ab52bda6f6226550218be2c7e8019f2370fc6792c47cfaf53009c8c4985acadf3ba95efb62c72edec9ce8278313b
7
- data.tar.gz: e6ddd8da17426c788b5fecd30164fb8fe051c58bbcd14fedc306e667c34d3ea25d73cdf32e6277d8d89f689936b1694d1435cb41011473f8cd5118e8a80f1946
6
+ metadata.gz: 876462422afe5f4c32b79c6bc5fa9a9310d43d8c8bcd4edca84b494950f0d59cc5eae5e1f352624875ccd2fb1497a7795f7bbcd40ba23681ba1e94ffe6d7cc27
7
+ data.tar.gz: 9b5514cffc95723a7331bd9a3183f05e3271fbcaf85e1a813562bb3b4469ac87e8aff57e040264637bbe16bf53d5612a4b70477fb79cae9124613966e72bb2dd
@@ -43,21 +43,3 @@ blocks:
43
43
  - name: RSpec Unit Tests
44
44
  commands:
45
45
  - bundle exec rake
46
-
47
- - name: Building Docker Image
48
- task:
49
-
50
- secrets:
51
- - name: GCP
52
-
53
- prologue:
54
- commands:
55
- - gcloud auth activate-service-account --key-file=.secrets/gcp.json
56
- - gcloud auth configure-docker -q eu.gcr.io
57
- - checkout
58
-
59
- jobs:
60
- - name: Building and pushing
61
- commands:
62
- - make build
63
- - test "$SEMAPHORE_GIT_BRANCH" = "master" && make push-latest || true
data/.tool-versions CHANGED
@@ -1,3 +1,2 @@
1
1
  ruby 3.1.2
2
2
  bundler 2.3.17
3
- golang 1.19
data/Rakefile CHANGED
@@ -16,21 +16,19 @@ GemHadar do
16
16
  'gospace'
17
17
  readme 'README.md'
18
18
  title "#{name.camelize}"
19
- executables %w[ betterlog betterlog_pusher betterlog_sink ]
19
+ executables %w[ betterlog ]
20
20
 
21
21
  dependency 'tins', '~>1.3', '>=1.22.0'
22
22
  dependency 'complex_config'
23
23
  dependency 'file-tail', '~>1.0'
24
24
  dependency 'json', '~>2.0'
25
25
  dependency 'term-ansicolor', '~>1.3'
26
- dependency 'redis', '>=2.8'
27
26
  dependency 'redlock'
28
27
  dependency 'excon'
29
28
 
30
29
  development_dependency 'rake'
31
30
  development_dependency 'rspec'
32
31
  development_dependency 'simplecov'
33
- development_dependency 'mock_redis'
34
32
  end
35
33
 
36
34
  task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.20.3
1
+ 1.1.0
data/betterlog.gemspec CHANGED
@@ -1,24 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.20.3 ruby lib
2
+ # stub: betterlog 1.1.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.20.3"
6
+ s.version = "1.1.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 = "2022-08-18"
11
+ s.date = "2023-02-10"
12
12
  s.description = "This library provides structure json logging for our rails projects".freeze
13
13
  s.email = "developers@betterplace.org".freeze
14
- s.executables = ["betterlog".freeze, "betterlog_pusher".freeze, "betterlog_sink".freeze]
15
- s.extra_rdoc_files = ["README.md".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze]
16
- s.files = [".github/workflows/codeql-analysis.yml".freeze, ".gitignore".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, "Dockerfile".freeze, "Gemfile".freeze, "LICENSE".freeze, "Makefile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "betterlog/config.go".freeze, "betterlog/healthz.go".freeze, "betterlog/redis_cert_cache.go".freeze, "bin/betterlog".freeze, "bin/betterlog_pusher".freeze, "bin/betterlog_sink".freeze, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".freeze, "go.mod".freeze, "go.sum".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_event_formatter_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/betterlog/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
14
+ s.executables = ["betterlog".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze]
16
+ s.files = [".github/workflows/codeql-analysis.yml".freeze, ".gitignore".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "bin/betterlog".freeze, "config/log.yml".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_event_formatter_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
17
17
  s.homepage = "http://github.com/betterplace/betterlog".freeze
18
18
  s.rdoc_options = ["--title".freeze, "Betterlog".freeze, "--main".freeze, "README.md".freeze]
19
- s.rubygems_version = "3.3.19".freeze
19
+ s.rubygems_version = "3.3.25".freeze
20
20
  s.summary = "Structured logging support for bp".freeze
21
- s.test_files = ["spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_event_formatter_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/betterlog/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
21
+ s.test_files = ["spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_event_formatter_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  s.specification_version = 4
@@ -29,13 +29,11 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency(%q<rake>.freeze, [">= 0"])
30
30
  s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
31
31
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
32
- s.add_development_dependency(%q<mock_redis>.freeze, [">= 0"])
33
32
  s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.22.0"])
34
33
  s.add_runtime_dependency(%q<complex_config>.freeze, [">= 0"])
35
34
  s.add_runtime_dependency(%q<file-tail>.freeze, ["~> 1.0"])
36
35
  s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0"])
37
36
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
38
- s.add_runtime_dependency(%q<redis>.freeze, [">= 2.8"])
39
37
  s.add_runtime_dependency(%q<redlock>.freeze, [">= 0"])
40
38
  s.add_runtime_dependency(%q<excon>.freeze, [">= 0"])
41
39
  else
@@ -43,13 +41,11 @@ Gem::Specification.new do |s|
43
41
  s.add_dependency(%q<rake>.freeze, [">= 0"])
44
42
  s.add_dependency(%q<rspec>.freeze, [">= 0"])
45
43
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
46
- s.add_dependency(%q<mock_redis>.freeze, [">= 0"])
47
44
  s.add_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.22.0"])
48
45
  s.add_dependency(%q<complex_config>.freeze, [">= 0"])
49
46
  s.add_dependency(%q<file-tail>.freeze, ["~> 1.0"])
50
47
  s.add_dependency(%q<json>.freeze, ["~> 2.0"])
51
48
  s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.3"])
52
- s.add_dependency(%q<redis>.freeze, [">= 2.8"])
53
49
  s.add_dependency(%q<redlock>.freeze, [">= 0"])
54
50
  s.add_dependency(%q<excon>.freeze, [">= 0"])
55
51
  end
@@ -10,6 +10,7 @@ module Betterlog
10
10
  thread_local(:data) { {} }
11
11
 
12
12
  def add(data_hash)
13
+ data_hash = data_hash.symbolize_keys_recursive
13
14
  data = data_hash | data
14
15
  Notifiers.context(data_hash)
15
16
  self
@@ -20,12 +20,15 @@ module Betterlog
20
20
  m = m.sub(/\s+$/, '')
21
21
 
22
22
  timestamp = timestamp.utc.iso8601(3)
23
- event = Log::Event.new(
23
+ event = Log::Event.new({
24
24
  emitter: emitter,
25
25
  timestamp: timestamp,
26
26
  message: m,
27
27
  severity: severity.to_s.downcase,
28
28
  # tags: current_tags,
29
+ meta: (
30
+ Sidekiq::Context.current&.symbolize_keys_recursive if defined?(Sidekiq::Context.current)
31
+ )}.compact
29
32
  )
30
33
  backtrace = m.scan(/^\s*(?:[^:]+):(?:\d+).*$/)
31
34
  if backtrace.size > 1
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.20.3'
3
+ VERSION = '1.1.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:
data/lib/betterlog.rb CHANGED
@@ -10,7 +10,6 @@ require 'betterlog/version'
10
10
  require 'betterlog/log'
11
11
  require 'betterlog/notifiers'
12
12
  require 'betterlog/global_metadata'
13
- require 'betterlog/logger'
14
13
 
15
14
  if defined? Rails
16
15
  require 'betterlog/railtie'
data/spec/spec_helper.rb CHANGED
@@ -9,11 +9,5 @@ begin
9
9
  require 'byebug'
10
10
  rescue LoadError
11
11
  end
12
- require 'mock_redis'
13
- class MockRedis
14
- class BaseConnectionError < StandardError; end
15
- class CannotConnectError < BaseConnectionError; end
16
- end
17
- Redis=MockRedis
18
12
  require 'betterlog'
19
13
  Betterlog::Log.default_logger = Logger.new(nil)
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.20.3
4
+ version: 1.1.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: 2022-08-18 00:00:00.000000000 Z
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: mock_redis
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: tins
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -156,20 +142,6 @@ dependencies:
156
142
  - - "~>"
157
143
  - !ruby/object:Gem::Version
158
144
  version: '1.3'
159
- - !ruby/object:Gem::Dependency
160
- name: redis
161
- requirement: !ruby/object:Gem::Requirement
162
- requirements:
163
- - - ">="
164
- - !ruby/object:Gem::Version
165
- version: '2.8'
166
- type: :runtime
167
- prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- version: '2.8'
173
145
  - !ruby/object:Gem::Dependency
174
146
  name: redlock
175
147
  requirement: !ruby/object:Gem::Requirement
@@ -202,8 +174,6 @@ description: This library provides structure json logging for our rails projects
202
174
  email: developers@betterplace.org
203
175
  executables:
204
176
  - betterlog
205
- - betterlog_pusher
206
- - betterlog_sink
207
177
  extensions: []
208
178
  extra_rdoc_files:
209
179
  - README.md
@@ -214,7 +184,6 @@ extra_rdoc_files:
214
184
  - lib/betterlog/log/event_formatter.rb
215
185
  - lib/betterlog/log/severity.rb
216
186
  - lib/betterlog/log_event_formatter.rb
217
- - lib/betterlog/logger.rb
218
187
  - lib/betterlog/notifiers.rb
219
188
  - lib/betterlog/railtie.rb
220
189
  - lib/betterlog/version.rb
@@ -223,26 +192,14 @@ files:
223
192
  - ".gitignore"
224
193
  - ".semaphore/semaphore.yml"
225
194
  - ".tool-versions"
226
- - Dockerfile
227
195
  - Gemfile
228
196
  - LICENSE
229
- - Makefile
230
197
  - README.md
231
198
  - Rakefile
232
- - TODO.md
233
199
  - VERSION
234
200
  - betterlog.gemspec
235
- - betterlog/config.go
236
- - betterlog/healthz.go
237
- - betterlog/redis_cert_cache.go
238
201
  - bin/betterlog
239
- - bin/betterlog_pusher
240
- - bin/betterlog_sink
241
- - cmd/betterlog-server/LICENSE
242
- - cmd/betterlog-server/main.go
243
202
  - config/log.yml
244
- - go.mod
245
- - go.sum
246
203
  - lib/betterlog.rb
247
204
  - lib/betterlog/global_metadata.rb
248
205
  - lib/betterlog/log.rb
@@ -250,7 +207,6 @@ files:
250
207
  - lib/betterlog/log/event_formatter.rb
251
208
  - lib/betterlog/log/severity.rb
252
209
  - lib/betterlog/log_event_formatter.rb
253
- - lib/betterlog/logger.rb
254
210
  - lib/betterlog/notifiers.rb
255
211
  - lib/betterlog/railtie.rb
256
212
  - lib/betterlog/version.rb
@@ -259,7 +215,6 @@ files:
259
215
  - spec/betterlog/log/severity_spec.rb
260
216
  - spec/betterlog/log_event_formatter_spec.rb
261
217
  - spec/betterlog/log_spec.rb
262
- - spec/betterlog/logger_spec.rb
263
218
  - spec/betterlog/version_spec.rb
264
219
  - spec/spec_helper.rb
265
220
  homepage: http://github.com/betterplace/betterlog
@@ -284,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
284
239
  - !ruby/object:Gem::Version
285
240
  version: '0'
286
241
  requirements: []
287
- rubygems_version: 3.3.19
242
+ rubygems_version: 3.3.25
288
243
  signing_key:
289
244
  specification_version: 4
290
245
  summary: Structured logging support for bp
@@ -294,6 +249,5 @@ test_files:
294
249
  - spec/betterlog/log/severity_spec.rb
295
250
  - spec/betterlog/log_event_formatter_spec.rb
296
251
  - spec/betterlog/log_spec.rb
297
- - spec/betterlog/logger_spec.rb
298
252
  - spec/betterlog/version_spec.rb
299
253
  - spec/spec_helper.rb
data/Dockerfile DELETED
@@ -1,49 +0,0 @@
1
- FROM golang:1.18-alpine AS builder
2
-
3
- # Update/Upgrade/Add packages for building
4
-
5
- RUN apk add --no-cache bash git build-base
6
-
7
- # Create appuser.
8
- ENV USER=appuser
9
- ENV UID=10001
10
-
11
- RUN adduser \
12
- --disabled-password \
13
- --gecos "" \
14
- --home "/none" \
15
- --shell "/sbin/nologin" \
16
- --no-create-home \
17
- --uid "${UID}" \
18
- "${USER}"
19
-
20
-
21
- # Build betterlog
22
-
23
- WORKDIR /build/betterlog
24
-
25
- ADD . .
26
-
27
- ENV GOPATH=/build/betterlog/gospace
28
-
29
- RUN make clobber
30
-
31
- RUN make setup all
32
-
33
- RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags='-w -s' -o betterlog-server cmd/betterlog-server/main.go
34
-
35
- FROM scratch AS runner
36
-
37
- COPY --from=builder /etc/passwd /etc/passwd
38
-
39
- COPY --from=builder /etc/group /etc/group
40
-
41
- COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
42
-
43
- WORKDIR /
44
-
45
- COPY --from=builder --chown=appuser:appuser /build/betterlog/betterlog-server /
46
-
47
- EXPOSE 5514
48
-
49
- ENTRYPOINT [ "/betterlog-server" ]
data/Makefile DELETED
@@ -1,65 +0,0 @@
1
- DOCKER_IMAGE_LATEST = betterlog
2
- DOCKER_IMAGE = $(DOCKER_IMAGE_LATEST):$(REVISION_SHORT)
3
- PROJECT_ID = betterplace-183212
4
- REMOTE_LATEST_TAG := eu.gcr.io/${PROJECT_ID}/$(DOCKER_IMAGE_LATEST)
5
- REMOTE_TAG = eu.gcr.io/$(PROJECT_ID)/$(DOCKER_IMAGE)
6
- REVISION := $(shell git rev-parse HEAD)
7
- REVISION_SHORT := $(shell echo $(REVISION) | head -c 7)
8
- GOPATH := $(shell pwd)/gospace
9
- GOBIN = $(GOPATH)/bin
10
-
11
- .EXPORT_ALL_VARIABLES:
12
-
13
- all: betterlog-server
14
-
15
- betterlog-server: cmd/betterlog-server/main.go betterlog/*.go
16
- go build -o $@ $<
17
-
18
- local: betterlog-server
19
- REDIS_URL=$(REDIS_URL) ./betterlog-server
20
-
21
- setup: fake-package
22
- go mod download
23
-
24
- fake-package:
25
- rm -rf $(GOPATH)/src/github.com/betterplace/betterlog
26
- mkdir -p $(GOPATH)/src/github.com/betterplace
27
- ln -s $(shell pwd) $(GOPATH)/src/github.com/betterplace/betterlog
28
-
29
- coverage-display: coverage
30
- @go tool cover -html=coverage.out
31
-
32
- clean:
33
- @rm -f betterlog-server coverage.out tags
34
-
35
- clobber: clean
36
- @rm -rf $(GOPATH)/*
37
-
38
- tags: clean
39
- @gotags -tag-relative=false -silent=true -R=true -f $@ . $(GOPATH)
40
-
41
- build-info:
42
- @echo $(DOCKER_IMAGE)
43
-
44
- build:
45
- docker build --pull -t $(DOCKER_IMAGE) .
46
- $(MAKE) build-info
47
-
48
- build-force:
49
- docker build --pull -t $(DOCKER_IMAGE) --no-cache .
50
- $(MAKE) build-info
51
-
52
- server:
53
- docker run --rm -it $(DOCKER_IMAGE)
54
-
55
- pull:
56
- docker pull $(REMOTE_TAG)
57
- docker tag $(REMOTE_TAG) $(DOCKER_IMAGE)
58
-
59
- push: build
60
- docker tag $(DOCKER_IMAGE) $(REMOTE_TAG)
61
- docker push $(REMOTE_TAG)
62
-
63
- push-latest: push
64
- docker tag ${DOCKER_IMAGE} ${REMOTE_LATEST_TAG}
65
- docker push ${REMOTE_LATEST_TAG}
data/TODO.md DELETED
@@ -1 +0,0 @@
1
- - `complex_config` config files
data/betterlog/config.go DELETED
@@ -1,11 +0,0 @@
1
- package betterlog
2
-
3
- type Config struct {
4
- PORT int `default:"5514"`
5
- HEALTHZ_PORT int `default:"5513"`
6
- HTTP_REALM string `default:"betterlog"`
7
- HTTP_AUTH string
8
- SSL bool
9
- REDIS_PREFIX string
10
- REDIS_URL string `default:"redis://localhost:6379"`
11
- }
data/betterlog/healthz.go DELETED
@@ -1,71 +0,0 @@
1
- package betterlog
2
-
3
- import (
4
- "fmt"
5
- "log"
6
- "net/http"
7
- "os"
8
-
9
- "github.com/labstack/echo/v4"
10
- )
11
-
12
- type Health struct {
13
- PORT int
14
- }
15
-
16
- type Response struct {
17
- Hostname string `json:"hostname"`
18
- Healthy bool `json:"healthy"`
19
- Error string `json:"error,omitempty"`
20
- Message string `json:"message,omitempty"`
21
- }
22
-
23
- func determineHostname() string {
24
- hostname, err := os.Hostname()
25
- if err != nil {
26
- hostname = "unknown"
27
- }
28
- return hostname
29
- }
30
-
31
- func (health Health) Check() error {
32
- return nil
33
- }
34
-
35
- func (health Health) ZPage(next echo.HandlerFunc) echo.HandlerFunc {
36
- hostname := determineHostname()
37
- return func(c echo.Context) error {
38
- if c.Path() == "/healthz" {
39
- if err := health.Check(); err == nil {
40
- return c.JSON(
41
- http.StatusOK,
42
- Response{
43
- Hostname: hostname,
44
- Healthy: true,
45
- },
46
- )
47
- } else {
48
- log.Printf("error: %v", err)
49
- return c.JSON(
50
- http.StatusInternalServerError,
51
- Response{
52
- Hostname: hostname,
53
- Healthy: false,
54
- Error: err.Error(),
55
- Message: "problem detected",
56
- },
57
- )
58
- }
59
- } else {
60
- return next(c)
61
- }
62
- }
63
- }
64
-
65
- func StartHealthzEcho(health Health) {
66
- e := echo.New()
67
-
68
- e.Use(health.ZPage)
69
- log.Printf("Starting :%d/healthz", health.PORT)
70
- e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", health.PORT)))
71
- }
@@ -1,83 +0,0 @@
1
- package betterlog
2
-
3
- import (
4
- "context"
5
- "strings"
6
-
7
- "github.com/go-redis/redis"
8
- "golang.org/x/crypto/acme/autocert"
9
- )
10
-
11
- type RedisCertCache struct {
12
- Redis *redis.Client
13
- PREFIX string
14
- }
15
-
16
- // Get reads certificate data from the specified key name.
17
- func (cache RedisCertCache) Get(ctx context.Context, name string) ([]byte, error) {
18
- name = strings.Join([]string{cache.PREFIX, name}, "/")
19
- done := make(chan struct{})
20
- var (
21
- err error
22
- data string
23
- )
24
- go func() {
25
- defer close(done)
26
- result := cache.Redis.Get(name)
27
- err = result.Err()
28
- if err == nil {
29
- data, err = result.Result()
30
- }
31
- }()
32
- select {
33
- case <-ctx.Done():
34
- return nil, ctx.Err()
35
- case <-done:
36
- }
37
- if err == redis.Nil {
38
- return nil, autocert.ErrCacheMiss
39
- }
40
- return []byte(data), err
41
- }
42
-
43
- // Put writes the certificate data to the specified redis key name.
44
- func (cache RedisCertCache) Put(ctx context.Context, name string, data []byte) error {
45
- name = strings.Join([]string{cache.PREFIX, name}, "/")
46
- done := make(chan struct{})
47
- var err error
48
- go func() {
49
- defer close(done)
50
- select {
51
- case <-ctx.Done():
52
- // Don't overwrite the key if the context was canceled.
53
- default:
54
- result := cache.Redis.Set(name, string(data), 0)
55
- err = result.Err()
56
- }
57
- }()
58
- select {
59
- case <-ctx.Done():
60
- return ctx.Err()
61
- case <-done:
62
- }
63
- return err
64
- }
65
-
66
- // Delete removes the specified key name.
67
- func (cache RedisCertCache) Delete(ctx context.Context, name string) error {
68
- name = strings.Join([]string{cache.PREFIX, name}, "/")
69
- var (
70
- err error
71
- done = make(chan struct{})
72
- )
73
- go func() {
74
- defer close(done)
75
- err = cache.Redis.Del(name).Err()
76
- }()
77
- select {
78
- case <-ctx.Done():
79
- return ctx.Err()
80
- case <-done:
81
- }
82
- return err
83
- }
data/bin/betterlog_pusher DELETED
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # vim: set ft=ruby et sw=2 ts=2:
3
-
4
- require 'betterlog'
5
- require 'excon'
6
- require 'redlock'
7
-
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 =
14
- if redis_sentinels = ENV['REDIS_SENTINELS']&.split(?,)
15
- redis_sentinels.map! { |s|
16
- h, p = s.split(?:, 2)
17
- { host: h, port: (p || 26379).to_i }
18
- }
19
- Redis.new(url: redis_url, sentinels: redis_sentinels, role: :master)
20
- else
21
- Redis.new(url: redis_url)
22
- end
23
- lm = Redlock::Client.new([ redis_url ])
24
- logger = Betterlog::Logger.new(redis, name: name)
25
-
26
- quit = false
27
- [ :TERM, :INT, :QUIT ].each { |s| trap(s) { quit = true } }
28
-
29
- STDOUT.sync = true
30
- loop do
31
- count = 0
32
- lm.lock!(File.basename($0), lock_time) do
33
- print ?…
34
- logger.each_slice(lines).with_index do |batch, i|
35
- count.zero? and print ?○
36
- count += batch.sum(&:size)
37
- attempt(attempts: 10, sleep: -60, reraise: true) do
38
- print ?┄
39
- Excon.post(url, body: batch.join)
40
- end
41
- end
42
- end
43
- quit and exit
44
- if count.zero?
45
- sleep 1
46
- else
47
- print "→ %s sent.\n" % Tins::Unit.format(count, format: '%.2f %U', prefix: 1024, unit: ?b)
48
- end
49
- rescue Redlock::LockError => e
50
- STDERR.puts "Caught #{e.class}: #{e} => Retrying!"
51
- end
data/bin/betterlog_sink DELETED
@@ -1,47 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # vim: set ft=ruby et sw=2 ts=2:
3
-
4
- require 'betterlog'
5
- require 'complex_config/rude'
6
- require 'json'
7
-
8
- LOG_ENV = ENV.fetch('LOG_ENV', 'production')
9
-
10
- @config = complex_config.log(LOG_ENV).sink
11
-
12
- ENV['KUBECONFIG'] = File.join(
13
- ENV.fetch('HOME'),
14
- '.kube',
15
- @config.cluster.name
16
- )
17
-
18
- def authenticate
19
- return if File.exist?(ENV['KUBECONFIG'])
20
- context = [
21
- 'gke',
22
- @config.cluster.project,
23
- @config.cluster.zone,
24
- @config.cluster.name,
25
- ] * ?_
26
- system(%{
27
- gcloud --no-user-output-enabled container clusters get-credentials \
28
- #{@config.cluster.name.inspect} \
29
- --zone #{@config.cluster.zone.inspect} \
30
- --project #{@config.cluster.project.inspect}
31
- }) or fail "failed to authenticate for context #{context.inspect}"
32
- end
33
-
34
- authenticate
35
-
36
- pods = JSON(
37
- %x{ kubectl -n #{@config.namespace} -ojson get pods },
38
- object_class: JSON::GenericObject
39
- )
40
-
41
- if pod = pods.items.find { |i| i.metadata.labels.app == @config.source }
42
- system %{
43
- kubectl logs -n #{@config.namespace} #{ARGV.join(' ')} #{pod.metadata.name}
44
- }
45
- else
46
- exit 1
47
- end
@@ -1,13 +0,0 @@
1
- Copyright 2018 Florian Frank
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
@@ -1,83 +0,0 @@
1
- package main
2
-
3
- import (
4
- "fmt"
5
- "io/ioutil"
6
- "log"
7
- "net/http"
8
- "os"
9
- "strings"
10
-
11
- betterlog "github.com/betterplace/betterlog/betterlog"
12
- "github.com/go-redis/redis"
13
- "github.com/kelseyhightower/envconfig"
14
- "github.com/labstack/echo/v4"
15
- "github.com/labstack/echo/v4/middleware"
16
- )
17
-
18
- func postLogHandler(c echo.Context) error {
19
- body := c.Request().Body
20
- data, err := ioutil.ReadAll(body)
21
- if err == nil {
22
- defer body.Close()
23
- os.Stdout.Write(data)
24
- return c.NoContent(http.StatusOK)
25
- } else {
26
- return c.String(http.StatusInternalServerError, err.Error())
27
- }
28
- }
29
-
30
- func basicAuthConfig(config betterlog.Config) middleware.BasicAuthConfig {
31
- return middleware.BasicAuthConfig{
32
- Realm: config.HTTP_REALM,
33
- Validator: func(username, password string, c echo.Context) (bool, error) {
34
- httpAuth := strings.Split(config.HTTP_AUTH, ":")
35
- if username == httpAuth[0] && password == httpAuth[1] {
36
- return true, nil
37
- }
38
- return false, nil
39
- },
40
- }
41
- }
42
-
43
- func initializeRedis(config betterlog.Config) *redis.Client {
44
- options, err := redis.ParseURL(config.REDIS_URL)
45
- if err != nil {
46
- log.Panic(err)
47
- }
48
- options.MaxRetries = 3
49
- return redis.NewClient(options)
50
- }
51
-
52
- func main() {
53
- var config betterlog.Config
54
- err := envconfig.Process("", &config)
55
- if err != nil {
56
- log.Fatal(err)
57
- }
58
- e := echo.New()
59
-
60
- if !config.SSL {
61
- e.Use(betterlog.Health{}.ZPage)
62
- }
63
- if config.HTTP_AUTH != "" {
64
- fmt.Println("info: Configuring HTTP Auth access control")
65
- e.Use(middleware.BasicAuthWithConfig(basicAuthConfig(config)))
66
- }
67
- e.POST("/log", postLogHandler)
68
- if config.SSL {
69
- log.Println("Starting SSL AutoTLS service.")
70
- redis := initializeRedis(config)
71
- e.AutoTLSManager.Cache = betterlog.RedisCertCache{
72
- Redis: redis,
73
- PREFIX: config.REDIS_PREFIX,
74
- }
75
- go betterlog.StartHealthzEcho(
76
- betterlog.Health{
77
- PORT: config.HEALTHZ_PORT,
78
- })
79
- e.Logger.Fatal(e.StartAutoTLS(fmt.Sprintf(":%d", config.PORT)))
80
- } else {
81
- e.Logger.Fatal(e.Start(fmt.Sprintf(":%d", config.PORT)))
82
- }
83
- }
data/go.mod DELETED
@@ -1,25 +0,0 @@
1
- module github.com/betterplace/betterlog
2
-
3
- go 1.19
4
-
5
- require (
6
- github.com/go-redis/redis v6.15.9+incompatible
7
- github.com/kelseyhightower/envconfig v1.4.0
8
- github.com/labstack/echo/v4 v4.8.0
9
- golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8
10
- )
11
-
12
- require (
13
- github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
14
- github.com/labstack/gommon v0.3.1 // indirect
15
- github.com/mattn/go-colorable v0.1.13 // indirect
16
- github.com/mattn/go-isatty v0.0.16 // indirect
17
- github.com/onsi/ginkgo v1.16.5 // indirect
18
- github.com/onsi/gomega v1.19.0 // indirect
19
- github.com/valyala/bytebufferpool v1.0.0 // indirect
20
- github.com/valyala/fasttemplate v1.2.1 // indirect
21
- golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
22
- golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect
23
- golang.org/x/text v0.3.7 // indirect
24
- golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
25
- )
data/go.sum DELETED
@@ -1,127 +0,0 @@
1
- github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2
- github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3
- github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4
- github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
5
- github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
6
- github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
7
- github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
8
- github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
9
- github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
10
- github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
11
- github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
12
- github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
13
- github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
14
- github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
15
- github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
16
- github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
17
- github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
18
- github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
19
- github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
20
- github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
21
- github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
22
- github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
23
- github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
24
- github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
25
- github.com/labstack/echo/v4 v4.7.2 h1:Kv2/p8OaQ+M6Ex4eGimg9b9e6icoxA42JSlOR3msKtI=
26
- github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
27
- github.com/labstack/echo/v4 v4.8.0 h1:wdc6yKVaHxkNOEdz4cRZs1pQkwSXPiRjq69yWP4QQS8=
28
- github.com/labstack/echo/v4 v4.8.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
29
- github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
30
- github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
31
- github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
32
- github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
33
- github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
34
- github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
35
- github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
36
- github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
37
- github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
38
- github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
39
- github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
40
- github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
41
- github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
42
- github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
43
- github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
44
- github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
45
- github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
46
- github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
47
- github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
48
- github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
49
- github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
50
- github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
51
- github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
52
- github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
53
- github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
54
- github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
55
- github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
56
- github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
57
- github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
58
- github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
59
- github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
60
- github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
61
- golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
62
- golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
63
- golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
64
- golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 h1:NvGWuYG8dkDHFSKksI1P9faiVJ9rayE6l0+ouWVIDs8=
65
- golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
66
- golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 h1:GIAS/yBem/gq2MUqgNIzUHW7cJMmx3TGZOrnyYaNQ6c=
67
- golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
68
- golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
69
- golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
70
- golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
71
- golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
72
- golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
73
- golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
74
- golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
75
- golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
76
- golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
77
- golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
78
- golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
79
- golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
80
- golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
81
- golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
82
- golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
83
- golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
84
- golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
85
- golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
86
- golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
87
- golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
88
- golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
89
- golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
90
- golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
91
- golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
92
- golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
93
- golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
94
- golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
95
- golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
96
- golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 h1:fqTvyMIIj+HRzMmnzr9NtpHP6uVpvB5fkHcgPDC4nu8=
97
- golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
98
- golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
99
- golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
100
- golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
101
- golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
102
- golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
103
- golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
104
- golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
105
- golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
106
- golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
107
- golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
108
- golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
109
- golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
110
- golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
111
- google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
112
- google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
113
- google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
114
- google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
115
- google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
116
- google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
117
- gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
118
- gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
119
- gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
120
- gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
121
- gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
122
- gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
123
- gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
124
- gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
125
- gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
126
- gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
127
- gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@@ -1,143 +0,0 @@
1
- begin
2
- require 'redis' unless defined?(Redis)
3
- rescue LoadError
4
- end
5
- require 'logger'
6
-
7
- module Betterlog
8
- class Logger < ::Logger
9
- include ComplexConfig::Provider::Shortcuts
10
-
11
- def initialize(redis, shift_age = 0, shift_size = 1048576, name: nil, buffer_size: nil, **opts)
12
- @redis = redis
13
- @fallback = ::Logger.new(STDERR)
14
- if level = cc.log.level?
15
- self.level = level
16
- @fallback.level = level
17
- end
18
- @name = name || self.class.name
19
- @buffer_size = determine_buffer_size(buffer_size)
20
- super(nil, shift_age, shift_size, **opts)
21
- end
22
-
23
- def self.for_redis_url(url, shift_age = 0, shift_size = 1048576, **opts)
24
- redis = Redis.new(url: url)
25
- redis.ping
26
- new(redis, shift_age, shift_size, **opts)
27
- rescue Redis::CannotConnectError
28
- end
29
-
30
- private def determine_buffer_size(buffer_size)
31
- if buffer_size.nil? || buffer_size < 1 * 1024 ** 2
32
- 1 * 1024 ** 2 # Default to very small buffer
33
- elsif buffer_size > 511 * 1024 ** 2
34
- 511 * 1024 ** 2 # Stay well below redis' 512Mb upper limit for strings
35
- else
36
- buffer_size
37
- end
38
- end
39
-
40
- private def redis_write(msg)
41
- # Stop before reaching configured buffer_size limit, after warning a lot.
42
- if @redis.strlen(@name) > (@buffer_size * 96) / 100
43
- @fallback.error("Redis memory limit will soon be reached =>"\
44
- " Log output to redis stops now unless log data is pushed away!")
45
- return nil
46
- end
47
- @redis.append @name, msg
48
- self
49
- end
50
-
51
-
52
- def add(severity, message = nil, progname = nil)
53
- severity ||= UNKNOWN
54
- if severity < @level
55
- return true
56
- end
57
- if progname.nil?
58
- progname = @progname
59
- end
60
- if message.nil?
61
- if block_given?
62
- message = yield
63
- else
64
- message = progname
65
- progname = @progname
66
- end
67
- end
68
- redis_write(
69
- format_message(format_severity(severity), Time.now, progname, message))
70
- true
71
- rescue Redis::BaseConnectionError
72
- @fallback.add(severity, message, progname)
73
- end
74
-
75
- def <<(msg)
76
- redis_write(msg)
77
- rescue Redis::BaseConnectionError
78
- @fallback << msg
79
- end
80
-
81
- def clear
82
- @redis.del @name
83
- self
84
- end
85
-
86
- def each_chunk(chunk_size: 100 * 1024, &block)
87
- chunk_size > 0 or raise ArgumentError, 'chunk_size > 0 required'
88
-
89
- # Delete any remaining temporary keys if we were interrtupted earlier
90
- # (or in some other process.)
91
- @redis.scan_each(match: "#{@name}_*") do |key|
92
- @redis.del key
93
- rescue Redis::BaseConnectionError
94
- end
95
-
96
- @redis.exists?(@name) or return Enumerator.new {}
97
-
98
- Enumerator.new do |y|
99
- name_tmp = "#{@name}_#{rand}"
100
- @redis.rename @name, name_tmp
101
-
102
- s = 0
103
- e = @redis.strlen(name_tmp) - 1
104
- until s > e
105
- range = @redis.getrange(name_tmp, s, s + chunk_size - 1)
106
- range.force_encoding 'ASCII-8BIT'
107
- y.yield range
108
- s += chunk_size
109
- end
110
-
111
- ensure
112
- begin
113
- @redis.del name_tmp
114
- rescue Redis::BaseConnectionError
115
- # We have to delete this later if del command failed here,
116
- # see the beginning of this method.
117
- end
118
- end.each(&block)
119
-
120
- rescue Redis::BaseConnectionError => e
121
- # Maybe it works again later, just log the error…
122
- @fallback.error(e)
123
- Enumerator.new {}
124
- end
125
-
126
- def each(chunk_size: 100 * 1024, &block)
127
- chunk_size > 0 or raise ArgumentError, 'chunk_size > 0 required'
128
- Enumerator.new do |y|
129
- buffer = ''
130
- buffer.encode! 'ASCII-8BIT'
131
- each_chunk(chunk_size: chunk_size) do |chunk|
132
- buffer << chunk
133
- buffer.gsub!(/\A(.*?#$/)/n) do |line|
134
- y.yield(line)
135
- ''
136
- end
137
- end
138
- buffer.length > 0 and y.yield(buffer)
139
- end.each(&block)
140
- end
141
- include Enumerable
142
- end
143
- end
@@ -1,96 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Betterlog::Logger do
4
- let :logger do
5
- described_class.new(Redis.new)
6
- end
7
-
8
- describe '.for_redis_url' do
9
- it 'can handle not being able to connect to redis' do
10
- redis = double
11
- allow(redis).to receive(:ping).and_raise Redis::CannotConnectError
12
- allow(Redis).to receive(:new).with(url: 'the_url').and_return redis
13
- expect(Betterlog::Logger.for_redis_url('the_url')).to be_nil
14
- end
15
-
16
- it 'can connect to redis for the url' do
17
- redis = double(ping: 'PONG')
18
- allow(Redis).to receive(:new).with(url: 'the_url').and_return redis
19
- expect(Betterlog::Logger.for_redis_url('the_url')).to be_a Betterlog::Logger
20
- end
21
- end
22
-
23
- describe '#<<' do
24
- it 'writes to redis' do
25
- expect(logger.instance_variable_get(:@redis)).to receive(:append).
26
- with('Betterlog::Logger', 'foo')
27
- logger << 'foo'
28
- end
29
-
30
- it 'falls back if redis errors' do
31
- allow(logger.instance_variable_get(:@redis)).to receive(:append).
32
- and_raise(Redis::BaseConnectionError)
33
- expect(logger.instance_variable_get(:@fallback)).to\
34
- receive(:<<).with('foo')
35
- logger << 'foo'
36
- end
37
- end
38
-
39
- describe '#add' do
40
- it 'writes to redis' do
41
- expect(logger.instance_variable_get(:@redis)).to receive(:append).
42
- with('Betterlog::Logger', /INFO -- : foo/)
43
- logger.info 'foo'
44
- end
45
-
46
- it 'falls back if redis errors' do
47
- allow(logger.instance_variable_get(:@redis)).to receive(:append).
48
- and_raise(Redis::BaseConnectionError)
49
- expect(logger.instance_variable_get(:@fallback)).to\
50
- receive(:add).with(::Logger::INFO, 'foo', nil)
51
- logger.info 'foo'
52
- end
53
- end
54
-
55
- describe '#each_chunk' do
56
- it 'iterates over chunks of data' do
57
- logger.clear
58
- logger << "foo" * 23
59
- expect(logger.each_chunk(chunk_size: 10).to_a).to eq %w[
60
- foofoofoof
61
- oofoofoofo
62
- ofoofoofoo
63
- foofoofoof
64
- oofoofoofo
65
- ofoofoofoo
66
- foofoofoo
67
- ]
68
- end
69
-
70
- it 'works if no data is there' do
71
- logger.clear
72
- expect(logger.each_chunk(chunk_size: 1).to_a).to eq []
73
- end
74
-
75
- it 'iterates if chunk_size is 1 and 23' do
76
- logger.clear
77
- logger << ?. * 23
78
- expect(logger.each_chunk(chunk_size: 1).to_a).to eq [ ?. ] * 23
79
- end
80
-
81
- it 'iterates if chunk_size is 1 and 22' do
82
- logger.clear
83
- logger << ?. * 22
84
- expect(logger.each_chunk(chunk_size: 1).to_a).to eq [ ?. ] * 22
85
- end
86
- end
87
-
88
- describe '#each' do
89
- it 'iterates over log lines' do
90
- logger.clear
91
- logger << "foo\n"
92
- logger << "bar\n"
93
- expect(logger.to_a).to eq [ "foo\n", "bar\n" ]
94
- end
95
- end
96
- end