betterlog 0.12.2 → 0.15.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: 19d827dd5737b98f60f8e2a6aa64d3f9651d976b2f30a0547154d48e45a893f8
4
- data.tar.gz: 488821623937b7b5143759afa38ca371cbb5541340423b8ca441e57904c26299
3
+ metadata.gz: 12593a18d28fc916e5c30257103937523a972f44a588087dd929742d99043b37
4
+ data.tar.gz: d0db15ffbe77f7f088c61c073c72a6847a79b07fd9c7f075fa4b8acdfdedaf50
5
5
  SHA512:
6
- metadata.gz: 158de8bb4b4de6006b24d99b4f5cc709c91445438e49479fa55d1dcd52e78ae6153c9039022c92aa2832f88e721b068c82094b32ef054772cd5c6a759ec23a79
7
- data.tar.gz: 4fface48b8f0a17697b14ed24cfebff578b2621c09a8a15c199aa518cd0d978c2f7423154ccf4c548fbb6ad088b24de79ec35404e1f80a45d980afbf80f53eb9
6
+ metadata.gz: 7e1b2ff2e6ac4bbe60eefcf48755e143fda9eb122c3392a9cba45e8996df5473903f4bb2a36bb657b1a80acf451215bf377782a33ba447ac61bad5ee7723644f
7
+ data.tar.gz: fca5f361f59320ed444e87f49a620a19b6e9a8d446b1e5c2e8255249915ffbe705787a660cf687c265105c60e24e9768ac427f360b18dafb4b282bf827aa7407
@@ -0,0 +1,60 @@
1
+ version: v1.0
2
+ name: Betterlog pipeline
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu1804
7
+
8
+ blocks:
9
+ - name: Caching
10
+ task:
11
+ prologue:
12
+ commands:
13
+ - checkout
14
+ jobs:
15
+ - name: cache bundle
16
+ commands:
17
+ - sem-version ruby 2.7.2
18
+ - cache restore gems-$SEMAPHORE_GIT_BRANCH,gems-master
19
+ - bundle config jobs $(getconf _NPROCESSORS_ONLN)
20
+ - bundle install
21
+ - cache store gems-$SEMAPHORE_GIT_BRANCH vendor/bundle
22
+
23
+ - name: "Unit tests"
24
+ task:
25
+ env_vars:
26
+ - name: RAILS_ENV
27
+ value: test
28
+ prologue:
29
+ commands:
30
+ - checkout
31
+
32
+ # Setup ruby
33
+ - sem-version ruby 2.7.2
34
+
35
+ # Setup gems
36
+ - cache restore gems-$SEMAPHORE_GIT_BRANCH,gems-master
37
+ - bundle config jobs $(getconf _NPROCESSORS_ONLN)
38
+ - bundle install
39
+
40
+ jobs:
41
+ - name: RSpec Unit Tests
42
+ commands:
43
+ - rake
44
+
45
+ - name: Building Docker Image
46
+ task:
47
+
48
+ secrets:
49
+ - name: GCP
50
+
51
+ prologue:
52
+ commands:
53
+ - gcloud auth activate-service-account --key-file=.secrets/gcp.json
54
+ - gcloud auth configure-docker -q
55
+ - checkout
56
+
57
+ jobs:
58
+ - name: Building and pushing
59
+ commands:
60
+ - make build push-latest
data/Dockerfile CHANGED
@@ -1,6 +1,4 @@
1
- ARG BASE_IMAGE
2
-
3
- FROM ${BASE_IMAGE} AS builder
1
+ FROM alpine:3.12.1 AS builder
4
2
 
5
3
  # Update/Upgrade/Add packages for building
6
4
 
@@ -18,9 +16,9 @@ RUN make clobber
18
16
 
19
17
  RUN go get -u github.com/betterplace/go-init
20
18
 
21
- RUN make fetch all
19
+ RUN make setup all
22
20
 
23
- FROM ${BASE_IMAGE} AS runner
21
+ FROM alpine:3.12.1 AS runner
24
22
 
25
23
  # Update/Upgrade/Add packages
26
24
 
data/Makefile CHANGED
@@ -1,4 +1,3 @@
1
- # Pass BASE_IMAGE=alpine:3.13.3
2
1
  DOCKER_IMAGE_LATEST = betterlog
3
2
  DOCKER_IMAGE = $(DOCKER_IMAGE_LATEST):$(REVISION_SHORT)
4
3
  PROJECT_ID = betterplace-183212
@@ -19,7 +18,7 @@ betterlog-server: cmd/betterlog-server/main.go betterlog/*.go
19
18
  local: betterlog-server
20
19
  REDIS_URL=$(REDIS_URL) ./betterlog-server
21
20
 
22
- fetch: fake-package
21
+ setup: fake-package
23
22
  go mod download
24
23
 
25
24
  fake-package:
@@ -48,15 +47,12 @@ tags: clean
48
47
  build-info:
49
48
  @echo $(DOCKER_IMAGE)
50
49
 
51
- pull-base:
52
- docker pull $(BASE_IMAGE)
53
-
54
- build: pull-base
55
- docker build -t $(DOCKER_IMAGE) --build-arg=BASE_IMAGE=$(BASE_IMAGE) .
50
+ build:
51
+ docker build -t $(DOCKER_IMAGE) .
56
52
  $(MAKE) build-info
57
53
 
58
- build-force: pull-base
59
- docker build -t $(DOCKER_IMAGE) --build-arg=BASE_IMAGE=$(BASE_IMAGE) --no-cache .
54
+ build-force:
55
+ docker build -t $(DOCKER_IMAGE) --no-cache .
60
56
  $(MAKE) build-info
61
57
 
62
58
  debug:
data/Rakefile CHANGED
@@ -30,6 +30,7 @@ GemHadar do
30
30
  development_dependency 'rake'
31
31
  development_dependency 'rspec'
32
32
  development_dependency 'simplecov'
33
+ development_dependency 'mock_redis'
33
34
  end
34
35
 
35
36
  task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.12.2
1
+ 0.15.0
@@ -1,22 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.12.2 ruby lib
2
+ # stub: betterlog 0.15.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.12.2"
6
+ s.version = "0.15.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 = "2020-04-20"
11
+ s.date = "2020-11-02"
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]
15
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 = [".gitignore".freeze, ".travis.yml".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, "cloudbuild.yaml".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_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
16
+ s.files = [".gitignore".freeze, ".semaphore/semaphore.yml".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, "cloudbuild.yaml".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_spec.rb".freeze, "spec/betterlog/logger_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.1.2".freeze
19
+ s.rubygems_version = "3.1.4".freeze
20
20
  s.summary = "Structured logging support for bp".freeze
21
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_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
22
22
 
@@ -29,6 +29,7 @@ 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"])
32
33
  s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.22.0"])
33
34
  s.add_runtime_dependency(%q<complex_config>.freeze, [">= 0"])
34
35
  s.add_runtime_dependency(%q<file-tail>.freeze, ["~> 1.0"])
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
42
43
  s.add_dependency(%q<rake>.freeze, [">= 0"])
43
44
  s.add_dependency(%q<rspec>.freeze, [">= 0"])
44
45
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
46
+ s.add_dependency(%q<mock_redis>.freeze, [">= 0"])
45
47
  s.add_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.22.0"])
46
48
  s.add_dependency(%q<complex_config>.freeze, [">= 0"])
47
49
  s.add_dependency(%q<file-tail>.freeze, ["~> 1.0"])
@@ -7,14 +7,14 @@ require 'json'
7
7
 
8
8
  LOG_ENV = ENV.fetch('LOG_ENV', 'production')
9
9
 
10
+ @config = complex_config.log(LOG_ENV).sink
11
+
10
12
  ENV['KUBECONFIG'] = File.join(
11
13
  ENV.fetch('HOME'),
12
14
  '.kube',
13
- "betterlog-#{LOG_ENV}"
15
+ @config.cluster.name
14
16
  )
15
17
 
16
- @config = complex_config.log(LOG_ENV).sink
17
-
18
18
  def authenticate
19
19
  return if File.exist?(ENV['KUBECONFIG'])
20
20
  context = [
@@ -1,8 +1,6 @@
1
1
  steps:
2
2
  - name: eu.gcr.io/betterplace-183212/better-builder
3
- args: ['pull', '${_BASE_IMAGE}']
4
- - name: eu.gcr.io/betterplace-183212/better-builder
5
- args: ['build', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}', '--build-arg=BASE_IMAGE=${_BASE_IMAGE}', '.']
3
+ args: ['build', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}', '.']
6
4
  images:
7
5
  - 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA'
8
6
  - 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}'
@@ -1,8 +1,6 @@
1
1
  require 'tins/xt'
2
2
  require 'json'
3
- require 'logger'
4
- require 'time'
5
- require 'term/ansicolor'
3
+ require 'complex_config'
6
4
 
7
5
  module Betterlog
8
6
  end
@@ -13,7 +11,6 @@ require 'betterlog/global_metadata'
13
11
  require 'betterlog/logger'
14
12
 
15
13
  if defined? Rails
16
- require 'betterlog/log_event_formatter'
17
14
  require 'betterlog/railtie'
18
15
  end
19
16
 
@@ -7,12 +7,16 @@ require 'betterlog/log/severity'
7
7
  module Betterlog
8
8
  class Log
9
9
  include Tins::SexySingleton
10
+ extend ComplexConfig::Provider::Shortcuts
10
11
 
11
12
  class_attr_accessor :default_logger
12
13
  self.default_logger = Logger.new(STDERR)
14
+ if level = cc.log?&.level?
15
+ default_logger.level = level
16
+ end
13
17
 
14
18
  def logger
15
- defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new(STDERR)
19
+ defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : self.class.default_logger
16
20
  end
17
21
 
18
22
  # Logs a message on severity info.
@@ -1,7 +1,11 @@
1
+ require 'time'
2
+ require 'term/ansicolor'
3
+
1
4
  module Betterlog
2
5
  class Log
3
6
  class EventFormatter
4
7
  include Term::ANSIColor
8
+ include ComplexConfig::Provider::Shortcuts
5
9
 
6
10
  def initialize(event)
7
11
  @event = event
@@ -1,3 +1,5 @@
1
+ require 'logger'
2
+
1
3
  module Betterlog
2
4
  class Log
3
5
  class Severity
@@ -1,6 +1,7 @@
1
1
  module Betterlog
2
2
  class LogEventFormatter < ActiveSupport::Logger::Formatter
3
3
  include ActiveSupport::TaggedLogging::Formatter
4
+ include ComplexConfig::Provider::Shortcuts
4
5
 
5
6
  def emitter
6
7
  'legacy'
@@ -1,10 +1,20 @@
1
- require 'redis'
1
+ begin
2
+ require 'redis' unless defined?(Redis)
3
+ rescue LoadError
4
+ end
5
+ require 'logger'
2
6
 
3
7
  module Betterlog
4
8
  class Logger < ::Logger
9
+ include ComplexConfig::Provider::Shortcuts
10
+
5
11
  def initialize(redis, shift_age = 0, shift_size = 1048576, name: nil, buffer_size: nil, **opts)
6
12
  @redis = redis
7
13
  @fallback = ::Logger.new(STDERR)
14
+ if level = cc.log.level?
15
+ self.level = level
16
+ @fallback.level = level
17
+ end
8
18
  @name = name || self.class.name
9
19
  @buffer_size = determine_buffer_size(buffer_size)
10
20
  super(nil, shift_age, shift_size, **opts)
@@ -83,7 +93,7 @@ module Betterlog
83
93
  rescue Redis::BaseConnectionError
84
94
  end
85
95
 
86
- @redis.exists(@name) or return Enumerator.new {}
96
+ @redis.exists?(@name) or return Enumerator.new {}
87
97
 
88
98
  Enumerator.new do |y|
89
99
  name_tmp = "#{@name}_#{rand}"
@@ -92,7 +102,9 @@ module Betterlog
92
102
  s = 0
93
103
  e = @redis.strlen(name_tmp) - 1
94
104
  until s > e
95
- y.yield @redis.getrange(name_tmp, s, s + chunk_size - 1)
105
+ range = @redis.getrange(name_tmp, s, s + chunk_size - 1)
106
+ range.force_encoding 'ASCII-8BIT'
107
+ y.yield range
96
108
  s += chunk_size
97
109
  end
98
110
 
@@ -115,9 +127,10 @@ module Betterlog
115
127
  chunk_size > 0 or raise ArgumentError, 'chunk_size > 0 required'
116
128
  Enumerator.new do |y|
117
129
  buffer = ''
130
+ buffer.encode! 'ASCII-8BIT'
118
131
  each_chunk(chunk_size: chunk_size) do |chunk|
119
132
  buffer << chunk
120
- buffer.gsub!(/\A(.*?#$/)/) do |line|
133
+ buffer.gsub!(/\A(.*?#$/)/n) do |line|
121
134
  y.yield(line)
122
135
  ''
123
136
  end
@@ -1,6 +1,7 @@
1
1
  module Betterlog
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "betterlog_railtie.configure_rails_initialization" do
4
+ require 'betterlog/log_event_formatter'
4
5
  Rails.logger.formatter = Betterlog::LogEventFormatter.new
5
6
  end
6
7
  end
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.12.2'
3
+ VERSION = '0.15.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:
@@ -9,5 +9,11 @@ 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
12
18
  require 'betterlog'
13
19
  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.12.2
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-20 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -66,6 +66,20 @@ 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'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: tins
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -206,7 +220,7 @@ extra_rdoc_files:
206
220
  - lib/betterlog/version.rb
207
221
  files:
208
222
  - ".gitignore"
209
- - ".travis.yml"
223
+ - ".semaphore/semaphore.yml"
210
224
  - Dockerfile
211
225
  - Gemfile
212
226
  - LICENSE
@@ -248,7 +262,7 @@ files:
248
262
  homepage: http://github.com/betterplace/betterlog
249
263
  licenses: []
250
264
  metadata: {}
251
- post_install_message:
265
+ post_install_message:
252
266
  rdoc_options:
253
267
  - "--title"
254
268
  - Betterlog
@@ -267,8 +281,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
281
  - !ruby/object:Gem::Version
268
282
  version: '0'
269
283
  requirements: []
270
- rubygems_version: 3.1.2
271
- signing_key:
284
+ rubygems_version: 3.1.4
285
+ signing_key:
272
286
  specification_version: 4
273
287
  summary: Structured logging support for bp
274
288
  test_files:
@@ -1,6 +0,0 @@
1
- rvm:
2
- - 2.6
3
- - 2.7
4
- sudo: false
5
- services:
6
- - redis-server