From e3f5f3877e3aea27bbe1f45ac8099a8978321f50 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 11:02:47 +0400 Subject: [PATCH 01/26] update gemspec --- lib/logdna/version.rb | 3 --- logdna.gemspec | 14 ++------------ 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100755 lib/logdna/version.rb diff --git a/lib/logdna/version.rb b/lib/logdna/version.rb deleted file mode 100755 index 944e6b7..0000000 --- a/lib/logdna/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module LogDNA - VERSION = '1.3.0'.freeze -end diff --git a/logdna.gemspec b/logdna.gemspec index 1769c6e..cd4d9d0 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -1,29 +1,19 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'logdna/version' - Gem::Specification.new do |spec| spec.name = 'logdna' - spec.version = LogDNA::VERSION - spec.authors = 'Gun Woo Choi, Derek Zhou' + spec.version = '1.3.0'.freeze spec.email = 'support@logdna.com' - - spec.summary = 'LogDNA Ruby logger' + spec.summary = 'LogDNA Ruby Logger' spec.homepage = 'https://github.com/logdna/ruby' spec.license = 'MIT' - spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0' spec.add_runtime_dependency 'require_all', '~> 1.4' spec.add_runtime_dependency 'json', '~> 2.0' - spec.add_development_dependency 'bundler', '~> 1.13' spec.add_development_dependency 'rake', '~> 10.5' spec.add_development_dependency 'rspec', '~> 3.5' From 100e3ae49a96a72f0213bafd985ff769755d71ce Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 11:03:05 +0400 Subject: [PATCH 02/26] update gemspec --- logdna.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/logdna.gemspec b/logdna.gemspec index cd4d9d0..7acba41 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -1,6 +1,7 @@ Gem::Specification.new do |spec| spec.name = 'logdna' spec.version = '1.3.0'.freeze + spec.authors = 'Gun Woo Choi, Derek Zhou' spec.email = 'support@logdna.com' spec.summary = 'LogDNA Ruby Logger' spec.homepage = 'https://github.com/logdna/ruby' From c9ac08b0a0299957924fd4fec0a1d43d2b8fd71f Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 11:04:23 +0400 Subject: [PATCH 03/26] update gemspec --- logdna.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logdna.gemspec b/logdna.gemspec index 7acba41..dfab6de 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |spec| spec.name = 'logdna' spec.version = '1.3.0'.freeze - spec.authors = 'Gun Woo Choi, Derek Zhou' + spec.authors = 'Gun Woo Choi, Derek Zhou, Vilya Levitskiy, Muaz Siddiqui' spec.email = 'support@logdna.com' spec.summary = 'LogDNA Ruby Logger' spec.homepage = 'https://github.com/logdna/ruby' From c3d94c27f1af9d43d2f649b90ccb2447a2321b06 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 11:17:18 +0400 Subject: [PATCH 04/26] update gemspec and license --- LICENSE.txt => LICENSE | 10 +++++----- logdna.gemspec | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) rename LICENSE.txt => LICENSE (89%) mode change 100755 => 100644 diff --git a/LICENSE.txt b/LICENSE old mode 100755 new mode 100644 similarity index 89% rename from LICENSE.txt rename to LICENSE index 0f18fd1..37e8e3d --- a/LICENSE.txt +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 edwin-lai +Copyright (c) 2019 LogDNA Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/logdna.gemspec b/logdna.gemspec index dfab6de..154f752 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -6,9 +6,7 @@ Gem::Specification.new do |spec| spec.summary = 'LogDNA Ruby Logger' spec.homepage = 'https://github.com/logdna/ruby' spec.license = 'MIT' - spec.files = `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{^(test|spec|features)/}) - end + spec.files = ['**/*.rb', 'Gemfile', 'logdna.gemspec', 'README.md', 'LICENSE'] spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] From d887853b200402ffc7e00c73d3f3b9ebacd08b90 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 11:37:13 +0400 Subject: [PATCH 05/26] autocorrect offenses with rubocop --- .circleci/config.yml | 0 .ruby-version | 1 - Gemfile | 2 +- Rakefile | 2 +- lib/logdna.rb | 28 ++++++++------------- lib/logdna/client.rb | 5 +--- lib/logdna/resources.rb | 16 ++++++------ logdna.gemspec | 34 ++++++++++++------------- test.rb | 56 ----------------------------------------- 9 files changed, 39 insertions(+), 105 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 .ruby-version delete mode 100644 test.rb diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..e69de29 diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 24ba9a3..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -2.7.0 diff --git a/Gemfile b/Gemfile index bb242f2..98d1d05 100755 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in logdna_ruby.gemspec gemspec diff --git a/Rakefile b/Rakefile index b7e9ed5..c92b11e 100755 --- a/Rakefile +++ b/Rakefile @@ -3,4 +3,4 @@ require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task default: :spec diff --git a/lib/logdna.rb b/lib/logdna.rb index a3351cd..61c5f2e 100755 --- a/lib/logdna.rb +++ b/lib/logdna.rb @@ -60,9 +60,7 @@ def level=(value) end def log(message = nil, opts = {}) - if message.nil? && block_given? - message = yield - end + message = yield if message.nil? && block_given? if message.nil? puts "provide either a message or block" return @@ -70,22 +68,22 @@ def log(message = nil, opts = {}) message = message.to_s.encode("UTF-8") @client.write_to_buffer(message, default_opts.merge(opts).merge( timestamp: (Time.now.to_f * 1000).to_i - )) + )) end Resources::LOG_LEVELS.each do |lvl| name = lvl.downcase define_method name do |msg = nil, opts = {}, &block| - self.log(msg, opts.merge( - level: lvl - ), &block) + log(msg, opts.merge( + level: lvl + ), &block) end define_method "#{name}?" do - return Resources::LOG_LEVELS[self.level] == lvl if level.is_a? Numeric + return Resources::LOG_LEVELS[level] == lvl if level.is_a? Numeric - self.level == lvl + level == lvl end end @@ -99,7 +97,7 @@ def clear def <<(msg = nil, opts = {}) log(msg, opts.merge( level: "" - )) + )) end def add(*_arg) @@ -110,7 +108,7 @@ def add(*_arg) def unknown(msg = nil, opts = {}) log(msg, opts.merge( level: "UNKNOWN" - )) + )) end def datetime_format(*_arg) @@ -119,15 +117,11 @@ def datetime_format(*_arg) end def close - if !@client.nil? - @client.exitout - end + @client.exitout unless @client.nil? end at_exit do - if !@client.nil? - @client.exitout - end + @client.exitout unless @client.nil? end end end diff --git a/lib/logdna/client.rb b/lib/logdna/client.rb index b26434e..ddb3ab7 100755 --- a/lib/logdna/client.rb +++ b/lib/logdna/client.rb @@ -114,12 +114,9 @@ def send_request end def flush - if @lock.try_lock @flush_scheduled = false - if @buffer.any? || @side_messages.any? - send_request - end + send_request if @buffer.any? || @side_messages.any? @lock.unlock else schedule_flush diff --git a/lib/logdna/resources.rb b/lib/logdna/resources.rb index b1323c4..e0dd481 100755 --- a/lib/logdna/resources.rb +++ b/lib/logdna/resources.rb @@ -1,15 +1,15 @@ module Resources - LOG_LEVELS = ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'TRACE'].freeze - DEFAULT_REQUEST_HEADER = { 'Content-Type' => 'application/json; charset=UTF-8' }.freeze - DEFAULT_REQUEST_TIMEOUT = 180000 - MS_IN_A_DAY = 86400000 - MAX_REQUEST_TIMEOUT = 300000 - MAX_LINE_LENGTH = 32000 + LOG_LEVELS = %w[DEBUG INFO WARN ERROR FATAL TRACE].freeze + DEFAULT_REQUEST_HEADER = { "Content-Type" => "application/json; charset=UTF-8" }.freeze + DEFAULT_REQUEST_TIMEOUT = 180_000 + MS_IN_A_DAY = 86_400_000 + MAX_REQUEST_TIMEOUT = 300_000 + MAX_LINE_LENGTH = 32_000 MAX_INPUT_LENGTH = 80 RETRY_TIMEOUT = 60 FLUSH_INTERVAL = 0.25 - FLUSH_BYTE_LIMIT = 500000 - ENDPOINT = 'https://logs.logdna.com/logs/ingest'.freeze + FLUSH_BYTE_LIMIT = 500_000 + ENDPOINT = "https://logs.logdna.com/logs/ingest".freeze MAC_ADDR_CHECK = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/ IP_ADDR_CHECK = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ end diff --git a/logdna.gemspec b/logdna.gemspec index 154f752..2f17f86 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -1,20 +1,20 @@ Gem::Specification.new do |spec| - spec.name = 'logdna' - spec.version = '1.3.0'.freeze - spec.authors = 'Gun Woo Choi, Derek Zhou, Vilya Levitskiy, Muaz Siddiqui' - spec.email = 'support@logdna.com' - spec.summary = 'LogDNA Ruby Logger' - spec.homepage = 'https://github.com/logdna/ruby' - spec.license = 'MIT' - spec.files = ['**/*.rb', 'Gemfile', 'logdna.gemspec', 'README.md', 'LICENSE'] - spec.bindir = 'exe' + spec.name = "logdna" + spec.version = "1.3.0".freeze + spec.authors = "Gun Woo Choi, Derek Zhou, Vilya Levitskiy, Muaz Siddiqui" + spec.email = "support@logdna.com" + spec.summary = "LogDNA Ruby Logger" + spec.homepage = "https://github.com/logdna/ruby" + spec.license = "MIT" + spec.files = ["**/*.rb", "Gemfile", "logdna.gemspec", "README.md", "LICENSE"] + spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] - spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0' - spec.add_runtime_dependency 'require_all', '~> 1.4' - spec.add_runtime_dependency 'json', '~> 2.0' - spec.add_development_dependency 'bundler', '~> 1.13' - spec.add_development_dependency 'rake', '~> 10.5' - spec.add_development_dependency 'rspec', '~> 3.5' - spec.add_development_dependency 'webmock', '~> 2.3' + spec.require_paths = ["lib"] + spec.add_runtime_dependency "concurrent-ruby", "~> 1.0" + spec.add_runtime_dependency "json", "~> 2.0" + spec.add_runtime_dependency "require_all", "~> 1.4" + spec.add_development_dependency "bundler", "~> 1.13" + spec.add_development_dependency "rake", "~> 10.5" + spec.add_development_dependency "rspec", "~> 3.5" + spec.add_development_dependency "webmock", "~> 2.3" end diff --git a/test.rb b/test.rb deleted file mode 100644 index b554d4b..0000000 --- a/test.rb +++ /dev/null @@ -1,56 +0,0 @@ -require 'require_all' -require_all 'lib' - -options = { hostname: "new_ruby", meta: { :once => { :first => "nested1", :another => "nested2" } } } - -logger1 = Logdna::Ruby.new('Your API Key', options) - -logger1.log('**************** This is the start of test ****************') -logger1.env = 'STAGING' -logger1.app = 'HELLO' -logger1.warn('Warn message with Staging and Hello') -logger1.clear -logger1.log('Is everything back to normal?') - -logger1.log('Testing env app name change using log') -logger1.env = 'PRODUCTION' -logger1.app = 'CHANGED' -logger1.log('This should be stage = PRODUCTION and appname = CHANGED') -logger1.log('Testing env app name change using other messages') - -logger1.error('This is error message with env = DEVELOPMENT and appname = NIHAO', { :env => 'DEVELOPMENT', :app => 'NIHAO' }) -logger1.log('Should not stay as DEVELOPMENT and NIHAO') -logger1.env = 'DEVELOPMENT' -logger1.app = 'NIHAO' -logger1.log('Now should be DEVELOPMENT and NIHAO') -logger1.log('Logging metadata in trace level', { :meta => { :once => { :first => "nested1", :another => "nested2" } }, :level => "TRACE" }) - -logger1.level = Logger::DEBUG -logger1.log('This is debug message') -logger1.add('this should not be supported') -logger1.fatal('Does this continue as fatal?') -logger1.log('This should be debug') -logger1.level = Logger::WARN -logger1.log('**************** This is the end of test ****************') - -=begin -logger1.level = Logger::WARN -logger1.log('This should be warn') -logger1.trace('This should be trace') -logger1.log('Again warn level') - -logger1.log('Warn level log1') -logger1.info('Info level log1') -logger1.level = Logger::DEBUG -logger1.log('DEBUG log1') - -logger1.app = 'NEW APP NAME' -logger1.env = 'Staging' -logger1.level = 'INFO' - -logger1.level = 'INFO' -logger1.level == Logger::INFO - -logger1.log('are changes all updated') -=end -sleep 3 From 8375e7663fecc565e057272fce4a42951e3322f5 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 11:48:39 +0400 Subject: [PATCH 06/26] sanitize --- lib/logdna.rb | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/logdna.rb b/lib/logdna.rb index 61c5f2e..4e38c37 100755 --- a/lib/logdna.rb +++ b/lib/logdna.rb @@ -50,7 +50,7 @@ def default_opts } end - def level=(value) + def update_level=(value) if value.is_a? Numeric @level = Resources::LOG_LEVELS[value] return @@ -66,23 +66,18 @@ def log(message = nil, opts = {}) return end message = message.to_s.encode("UTF-8") - @client.write_to_buffer(message, default_opts.merge(opts).merge( - timestamp: (Time.now.to_f * 1000).to_i - )) + @client.write_to_buffer(message, default_opts.merge(opts).merge(timestamp: (Time.now.to_f * 1000).to_i)) end Resources::LOG_LEVELS.each do |lvl| name = lvl.downcase define_method name do |msg = nil, opts = {}, &block| - log(msg, opts.merge( - level: lvl - ), &block) + log(msg, opts.merge(level: lvl), &block) end define_method "#{name}?" do return Resources::LOG_LEVELS[level] == lvl if level.is_a? Numeric - level == lvl end end @@ -95,9 +90,7 @@ def clear end def <<(msg = nil, opts = {}) - log(msg, opts.merge( - level: "" - )) + log(msg, opts.merge(level: "")) end def add(*_arg) @@ -106,9 +99,7 @@ def add(*_arg) end def unknown(msg = nil, opts = {}) - log(msg, opts.merge( - level: "UNKNOWN" - )) + log(msg, opts.merge(level: "UNKNOWN")) end def datetime_format(*_arg) From 60cf520976829c0b5113d34a9f175067ee708871 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 12:05:55 +0400 Subject: [PATCH 07/26] return version.rb and update gemspec --- lib/logdna/version.rb | 3 +++ logdna.gemspec | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 lib/logdna/version.rb diff --git a/lib/logdna/version.rb b/lib/logdna/version.rb new file mode 100644 index 0000000..944e6b7 --- /dev/null +++ b/lib/logdna/version.rb @@ -0,0 +1,3 @@ +module LogDNA + VERSION = '1.3.0'.freeze +end diff --git a/logdna.gemspec b/logdna.gemspec index 2f17f86..3d871c4 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -1,12 +1,16 @@ +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'logdna/version' + Gem::Specification.new do |spec| spec.name = "logdna" - spec.version = "1.3.0".freeze + spec.version = LogDNA::VERSION spec.authors = "Gun Woo Choi, Derek Zhou, Vilya Levitskiy, Muaz Siddiqui" spec.email = "support@logdna.com" spec.summary = "LogDNA Ruby Logger" spec.homepage = "https://github.com/logdna/ruby" spec.license = "MIT" - spec.files = ["**/*.rb", "Gemfile", "logdna.gemspec", "README.md", "LICENSE"] + spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(%r{(.md|.rb|.gemspec|Gemfile|LICENSE)$}) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] From 74a6a285b211cb59f1ce5fdd004a06773455c534 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 12:07:25 +0400 Subject: [PATCH 08/26] remove Rakefile and .rspec since there is no example/case till having one --- .rspec | 2 -- Rakefile | 6 ------ 2 files changed, 8 deletions(-) delete mode 100755 .rspec delete mode 100755 Rakefile diff --git a/.rspec b/.rspec deleted file mode 100755 index 8c18f1a..0000000 --- a/.rspec +++ /dev/null @@ -1,2 +0,0 @@ ---format documentation ---color diff --git a/Rakefile b/Rakefile deleted file mode 100755 index c92b11e..0000000 --- a/Rakefile +++ /dev/null @@ -1,6 +0,0 @@ -require "bundler/gem_tasks" -require "rspec/core/rake_task" - -RSpec::Core::RakeTask.new(:spec) - -task default: :spec From 1a0c8837f962829b7b2ddf077345660a8fdb3822 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 12:19:17 +0400 Subject: [PATCH 09/26] sanitize and update configs --- .rubocop.yml | 8 ++++---- Gemfile | 4 +++- lib/logdna.rb | 5 +++-- lib/logdna/resources.rb | 8 +++++--- lib/logdna/version.rb | 4 +++- logdna.gemspec | 13 ++++++------- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 63b7ceb..9c6a1fb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,11 +56,11 @@ Style/CollectionMethods: # inject seems more common in the community. reduce: "inject" -Style/UnneededInterpolation: - Enabled: flase +Style/RedundantInterpolation: + Enabled: false Style/RescueStandardError: - Enabled: flase + Enabled: false # Either allow this style or don't. Marking it as safe with parenthesis # is silly. Let's try to live without them for now. @@ -83,7 +83,7 @@ Style/SignalException: # Suppressing exceptions can be perfectly fine, and be it to avoid to # explicitly type nil into the rescue since that's what you want to return, # or suppressing LoadError for optional dependencies -Lint/HandleExceptions: +Lint/SuppressedException: Enabled: false # { ... } for multi-line blocks is okay, follow Weirichs rule instead: diff --git a/Gemfile b/Gemfile index 98d1d05..18ca16e 100755 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,6 @@ +# frozen_string_literal: true + source "https://rubygems.org" -# Specify your gem's dependencies in logdna_ruby.gemspec +# Specify your gem's dependencies in logdna.gemspec gemspec diff --git a/lib/logdna.rb b/lib/logdna.rb index 4e38c37..01eeda0 100755 --- a/lib/logdna.rb +++ b/lib/logdna.rb @@ -78,6 +78,7 @@ def log(message = nil, opts = {}) define_method "#{name}?" do return Resources::LOG_LEVELS[level] == lvl if level.is_a? Numeric + level == lvl end end @@ -108,11 +109,11 @@ def datetime_format(*_arg) end def close - @client.exitout unless @client.nil? + @client&.exitout end at_exit do - @client.exitout unless @client.nil? + @client&.exitout end end end diff --git a/lib/logdna/resources.rb b/lib/logdna/resources.rb index e0dd481..8d9d91f 100755 --- a/lib/logdna/resources.rb +++ b/lib/logdna/resources.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Resources LOG_LEVELS = %w[DEBUG INFO WARN ERROR FATAL TRACE].freeze DEFAULT_REQUEST_HEADER = { "Content-Type" => "application/json; charset=UTF-8" }.freeze @@ -9,7 +11,7 @@ module Resources RETRY_TIMEOUT = 60 FLUSH_INTERVAL = 0.25 FLUSH_BYTE_LIMIT = 500_000 - ENDPOINT = "https://logs.logdna.com/logs/ingest".freeze - MAC_ADDR_CHECK = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/ - IP_ADDR_CHECK = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ + ENDPOINT = "https://logs.logdna.com/logs/ingest" + MAC_ADDR_CHECK = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/.freeze + IP_ADDR_CHECK = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.freeze end diff --git a/lib/logdna/version.rb b/lib/logdna/version.rb index 944e6b7..363dd5c 100644 --- a/lib/logdna/version.rb +++ b/lib/logdna/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module LogDNA - VERSION = '1.3.0'.freeze + VERSION = "1.3.0" end diff --git a/logdna.gemspec b/logdna.gemspec index 3d871c4..d5be15f 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -1,6 +1,8 @@ -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'logdna/version' +require "logdna/version" Gem::Specification.new do |spec| spec.name = "logdna" @@ -10,15 +12,12 @@ Gem::Specification.new do |spec| spec.summary = "LogDNA Ruby Logger" spec.homepage = "https://github.com/logdna/ruby" spec.license = "MIT" - spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(%r{(.md|.rb|.gemspec|Gemfile|LICENSE)$}) } + spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(/(.md|.rb|.gemspec|Gemfile|LICENSE)$/) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_runtime_dependency "concurrent-ruby", "~> 1.0" spec.add_runtime_dependency "json", "~> 2.0" spec.add_runtime_dependency "require_all", "~> 1.4" - spec.add_development_dependency "bundler", "~> 1.13" - spec.add_development_dependency "rake", "~> 10.5" - spec.add_development_dependency "rspec", "~> 3.5" - spec.add_development_dependency "webmock", "~> 2.3" + spec.add_development_dependency "rubocop", "~> 0.77" end From 99ef4fe7e73f7d412c512ddf8c17adf10bc0b191 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 12:37:43 +0400 Subject: [PATCH 10/26] finish up CircleCI Config --- .circleci/config.yml | 174 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index e69de29..25548a2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -0,0 +1,174 @@ +version: 2 +jobs: + test: + docker: + - image: circleci/ruby:2.7.0 + steps: + - checkout + - run: bundle install + - run: rubocop -c .rubocop.yml -a + build: + docker: + - image: circleci/ruby:2.7.0 + steps: + - checkout + - run: + name: Check Tagged Push + command: | + PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) + if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then + echo "There is mismatch:" + echo " TAG_VERSION: ${CIRCLE_TAG}" + echo " PKG_VERSION: v${PKG_VERSION}" + exit 1 + fi + - run: gem build logdna.gemspec + - persist_to_workspace: + root: . + paths: + - ./logdna-*.gem + app2pub: + machine: true + steps: + - attach_workspace: + at: . + - run: + name: Check Tagged Push + command: | + PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) + if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then + echo "There is mismatch:" + echo " TAG_VERSION: ${CIRCLE_TAG}" + echo " PKG_VERSION: v${PKG_VERSION}" + exit 1 + fi + - persist_to_workspace: + root: . + paths: + - ./logdna-*.gem + app2rel: + machine: true + steps: + - attach_workspace: + at: . + - run: + name: Check Tagged Push + command: | + PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) + if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then + echo "There is mismatch:" + echo " TAG_VERSION: ${CIRCLE_TAG}" + echo " PKG_VERSION: v${PKG_VERSION}" + exit 1 + fi + - persist_to_workspace: + root: . + paths: + - ./logdna-*.gem + publish: + docker: + - image: circleci/golang:1.12 + steps: + - attach_workspace: + at: . + - run: + name: Check Tagged Push + command: | + PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) + if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then + echo "There is mismatch:" + echo " TAG_VERSION: ${CIRCLE_TAG}" + echo " PKG_VERSION: v${PKG_VERSION}" + exit 1 + fi + - run: go get -u github.com/tcnksm/ghr + - run: + name: Create a Release + command: | + ghr \ + -n "LogDNA Ruby Logger ${CIRCLE_TAG}" \ + -t ${GITHUB_TOKEN} \ + -u ${CIRCLE_PROJECT_USERNAME} \ + -r ${CIRCLE_PROJECT_REPONAME} \ + -draft ${CIRCLE_TAG} ${CIRCLE_WORKING_DIRECTORY} + - persist_to_workspace: + root: . + paths: + - ./logdna-*.gem + release: + docker: + - image: circleci/ruby:2.7.0 + steps: + - attach_workspace: + at: . + - run: + name: Check Tagged Push + command: | + PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) + if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then + echo "There is mismatch:" + echo " TAG_VERSION: ${CIRCLE_TAG}" + echo " PKG_VERSION: v${PKG_VERSION}" + exit 1 + fi + - run: gem push logdna-${CIRCLE_TAG}.gem -k ${RUBYGEMS_API_KEY} +workflows: + version: 2 + update: + jobs: + - test: + filters: + tags: + only: /v[0-9]+\.[0-9]+\.[0-9]+/ + branches: + ignore: /.*/ + - build: + requires: + - test + filters: + branches: + ignore: /.*/ + tags: + only: /v[0-9]+\.[0-9]+\.[0-9]+/ + - app2pub: + type: approval + requires: + - build + filters: + branches: + ignore: /.*/ + tags: + only: /v[0-9]+\.[0-9]+\.[0-9]+/ + - publish: + requires: + - app2pub + filters: + branches: + ignore: /.*/ + tags: + only: /v[0-9]+\.[0-9]+\.[0-9]+/ + - app2rel: + type: approval + requires: + - publish + filters: + branches: + ignore: /.*/ + tags: + only: /v[0-9]+\.[0-9]+\.[0-9]+/ + - publish: + requires: + - app2rel + filters: + branches: + ignore: /.*/ + tags: + only: /v[0-9]+\.[0-9]+\.[0-9]+/ + test: + jobs: + - test: + filters: + branches: + only: /.*/ + tags: + ignore: /v[0-9]+\.[0-9]+\.[0-9]+/ \ No newline at end of file From 66198f9ad6fbcf41559293be670c1e335e4298c9 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 15:41:03 +0400 Subject: [PATCH 11/26] fix tagging issue --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 25548a2..2ac2569 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,7 +111,7 @@ jobs: echo " PKG_VERSION: v${PKG_VERSION}" exit 1 fi - - run: gem push logdna-${CIRCLE_TAG}.gem -k ${RUBYGEMS_API_KEY} + - run: gem push logdna-*.gem -k ${RUBYGEMS_API_KEY} workflows: version: 2 update: @@ -171,4 +171,4 @@ workflows: branches: only: /.*/ tags: - ignore: /v[0-9]+\.[0-9]+\.[0-9]+/ \ No newline at end of file + ignore: /v[0-9]+\.[0-9]+\.[0-9]+/ From a05c29ee20dcb09cf3fb834be7fd4a23632ee0c1 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 18:14:04 +0400 Subject: [PATCH 12/26] templatize the config --- .circleci/config.yml | 113 +++++++++++-------------------------------- 1 file changed, 27 insertions(+), 86 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ac2569..f56e15c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,14 @@ -version: 2 +version: 2.1 +tagged_build_filters: &tagged_build_filters + branches: + ignore: /.*/ + tags: + only: /v[0-9]+\.[0-9]+\.[0-9]+/ +test_build_filters: &test_build_filters + branches: + only: /.*/ + tags: + ignore: /v[0-9]+\.[0-9]+\.[0-9]+/ jobs: test: docker: @@ -32,35 +42,6 @@ jobs: steps: - attach_workspace: at: . - - run: - name: Check Tagged Push - command: | - PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) - if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then - echo "There is mismatch:" - echo " TAG_VERSION: ${CIRCLE_TAG}" - echo " PKG_VERSION: v${PKG_VERSION}" - exit 1 - fi - - persist_to_workspace: - root: . - paths: - - ./logdna-*.gem - app2rel: - machine: true - steps: - - attach_workspace: - at: . - - run: - name: Check Tagged Push - command: | - PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) - if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then - echo "There is mismatch:" - echo " TAG_VERSION: ${CIRCLE_TAG}" - echo " PKG_VERSION: v${PKG_VERSION}" - exit 1 - fi - persist_to_workspace: root: . paths: @@ -71,16 +52,6 @@ jobs: steps: - attach_workspace: at: . - - run: - name: Check Tagged Push - command: | - PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) - if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then - echo "There is mismatch:" - echo " TAG_VERSION: ${CIRCLE_TAG}" - echo " PKG_VERSION: v${PKG_VERSION}" - exit 1 - fi - run: go get -u github.com/tcnksm/ghr - run: name: Create a Release @@ -95,80 +66,50 @@ jobs: root: . paths: - ./logdna-*.gem + app2rel: + machine: true + steps: + - attach_workspace: + at: . + - persist_to_workspace: + root: . + paths: + - ./logdna-*.gem release: docker: - image: circleci/ruby:2.7.0 steps: - attach_workspace: at: . - - run: - name: Check Tagged Push - command: | - PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) - if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then - echo "There is mismatch:" - echo " TAG_VERSION: ${CIRCLE_TAG}" - echo " PKG_VERSION: v${PKG_VERSION}" - exit 1 - fi - run: gem push logdna-*.gem -k ${RUBYGEMS_API_KEY} workflows: - version: 2 update: jobs: - test: - filters: - tags: - only: /v[0-9]+\.[0-9]+\.[0-9]+/ - branches: - ignore: /.*/ + filters: *tagged_build_filters - build: requires: - test - filters: - branches: - ignore: /.*/ - tags: - only: /v[0-9]+\.[0-9]+\.[0-9]+/ + filters: *tagged_build_filters - app2pub: type: approval requires: - build - filters: - branches: - ignore: /.*/ - tags: - only: /v[0-9]+\.[0-9]+\.[0-9]+/ + filters: *tagged_build_filters - publish: requires: - app2pub - filters: - branches: - ignore: /.*/ - tags: - only: /v[0-9]+\.[0-9]+\.[0-9]+/ + filters: *tagged_build_filters - app2rel: type: approval requires: - publish - filters: - branches: - ignore: /.*/ - tags: - only: /v[0-9]+\.[0-9]+\.[0-9]+/ + filters: *tagged_build_filters - publish: requires: - app2rel - filters: - branches: - ignore: /.*/ - tags: - only: /v[0-9]+\.[0-9]+\.[0-9]+/ + filters: *tagged_build_filters test: jobs: - test: - filters: - branches: - only: /.*/ - tags: - ignore: /v[0-9]+\.[0-9]+\.[0-9]+/ + filters: *test_build_filters From 81496c900eee07a6623e682b477074ea667f4a17 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 18:34:30 +0400 Subject: [PATCH 13/26] shorten bash command pipe --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f56e15c..efaf250 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: - run: name: Check Tagged Push command: | - PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'=' -f2 | cut -d'"' -f2) + PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'"' -f4) if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then echo "There is mismatch:" echo " TAG_VERSION: ${CIRCLE_TAG}" From 11786941c4fe309926a5b3219a4737afc9fae09b Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Mon, 16 Dec 2019 18:43:23 +0400 Subject: [PATCH 14/26] fix the bug --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index efaf250..1a06d3a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: - run: name: Check Tagged Push command: | - PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'"' -f4) + PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'"' -f2) if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then echo "There is mismatch:" echo " TAG_VERSION: ${CIRCLE_TAG}" From e28937e6148eab61abdcf01c16573265dbc59d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20J=C3=B6nsson?= Date: Tue, 17 Dec 2019 21:17:18 +0100 Subject: [PATCH 15/26] CircleCI: minor improvement Remove unnecessary use of cat. --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a06d3a..de275ed 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: - run: name: Check Tagged Push command: | - PKG_VERSION=$(cat lib/logdna/version.rb | grep VERSION | cut -d'"' -f2) + PKG_VERSION=$(grep VERSION lib/version.rb | cut -d'"' -f2) if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then echo "There is mismatch:" echo " TAG_VERSION: ${CIRCLE_TAG}" From 8caeca69a203aaac82c8ba6bf93f2b85a11101d2 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Thu, 19 Dec 2019 13:57:17 +0400 Subject: [PATCH 16/26] rearrange jobs --- .circleci/config.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a06d3a..7019169 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,7 @@ jobs: root: . paths: - ./logdna-*.gem - app2pub: + app2rel: machine: true steps: - attach_workspace: @@ -46,7 +46,7 @@ jobs: root: . paths: - ./logdna-*.gem - publish: + release: docker: - image: circleci/golang:1.12 steps: @@ -66,7 +66,7 @@ jobs: root: . paths: - ./logdna-*.gem - app2rel: + app2pub: machine: true steps: - attach_workspace: @@ -75,7 +75,7 @@ jobs: root: . paths: - ./logdna-*.gem - release: + publish: docker: - image: circleci/ruby:2.7.0 steps: @@ -91,23 +91,23 @@ workflows: requires: - test filters: *tagged_build_filters - - app2pub: + - app2rel: type: approval requires: - build filters: *tagged_build_filters - - publish: + - release: requires: - - app2pub + - app2rel filters: *tagged_build_filters - - app2rel: + - app2pub: type: approval requires: - - publish + - release filters: *tagged_build_filters - publish: requires: - - app2rel + - app2pub filters: *tagged_build_filters test: jobs: From 07729b8e0ad52137c2e647ff24e269adb1b8b540 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Thu, 19 Dec 2019 14:36:16 +0400 Subject: [PATCH 17/26] no need for app2rel --- .circleci/config.yml | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 844eedb..8a79248 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,15 +37,6 @@ jobs: root: . paths: - ./logdna-*.gem - app2rel: - machine: true - steps: - - attach_workspace: - at: . - - persist_to_workspace: - root: . - paths: - - ./logdna-*.gem release: docker: - image: circleci/golang:1.12 @@ -66,7 +57,7 @@ jobs: root: . paths: - ./logdna-*.gem - app2pub: + approve: machine: true steps: - attach_workspace: @@ -91,23 +82,18 @@ workflows: requires: - test filters: *tagged_build_filters - - app2rel: - type: approval - requires: - - build - filters: *tagged_build_filters - release: requires: - - app2rel + - build filters: *tagged_build_filters - - app2pub: + - approve: type: approval requires: - release filters: *tagged_build_filters - publish: requires: - - app2pub + - approve filters: *tagged_build_filters test: jobs: From f06bfad62cde98dac810e6799ac0256d62d68c9c Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 21:16:06 +0400 Subject: [PATCH 18/26] revert codebase back to the master --- .rubocop.yml | 30 ++++++++++++++++++++++++++---- lib/logdna.rb | 34 ++++++++++++++++++++++++---------- lib/logdna/client.rb | 5 ++++- lib/logdna/resources.rb | 22 ++++++++++------------ lib/logdna/version.rb | 4 +--- 5 files changed, 65 insertions(+), 30 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9c6a1fb..e50c1ff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -60,14 +60,12 @@ Style/RedundantInterpolation: Enabled: false Style/RescueStandardError: - Enabled: false + Enabled: false # Either allow this style or don't. Marking it as safe with parenthesis # is silly. Let's try to live without them for now. Style/ParenthesesAroundCondition: AllowSafeAssignment: false -Lint/AssignmentInCondition: - AllowSafeAssignment: false # A specialized exception class will take one or more arguments and construct the message from it. # So both variants make sense. @@ -80,6 +78,9 @@ Style/RaiseArgs: Style/SignalException: EnforcedStyle: only_raise +Style/GuardClause: + Enabled: false + # Suppressing exceptions can be perfectly fine, and be it to avoid to # explicitly type nil into the rescue since that's what you want to return, # or suppressing LoadError for optional dependencies @@ -110,6 +111,9 @@ Style/SingleLineBlockParams: Lint/ShadowingOuterLocalVariable: Enabled: false +Lint/AssignmentInCondition: + Enabled: false + # Check with yard instead. Style/Documentation: Enabled: false @@ -122,10 +126,28 @@ Naming/BinaryOperatorParameterName: # also they'll fail CI anyway Lint/Debugger: Enabled: false - +Lint/UnusedLocalVariable: + Enabled: true +Security/Eval: + Enabled: false # Style preference Style/MethodDefParentheses: Enabled: false Style/TrailingCommaInHashLiteral: Enabled: false + +Style/IfUnlessModifier: + Enabled: false + +Lint/DuplicateMethods: + Enabled: false + +Style/RedundantSelf: + Enabled: false + +Style/NegatedIf: + Enabled: false + +Style/SafeNavigation: + Enabled: false diff --git a/lib/logdna.rb b/lib/logdna.rb index 01eeda0..a3351cd 100755 --- a/lib/logdna.rb +++ b/lib/logdna.rb @@ -50,7 +50,7 @@ def default_opts } end - def update_level=(value) + def level=(value) if value.is_a? Numeric @level = Resources::LOG_LEVELS[value] return @@ -60,26 +60,32 @@ def update_level=(value) end def log(message = nil, opts = {}) - message = yield if message.nil? && block_given? + if message.nil? && block_given? + message = yield + end if message.nil? puts "provide either a message or block" return end message = message.to_s.encode("UTF-8") - @client.write_to_buffer(message, default_opts.merge(opts).merge(timestamp: (Time.now.to_f * 1000).to_i)) + @client.write_to_buffer(message, default_opts.merge(opts).merge( + timestamp: (Time.now.to_f * 1000).to_i + )) end Resources::LOG_LEVELS.each do |lvl| name = lvl.downcase define_method name do |msg = nil, opts = {}, &block| - log(msg, opts.merge(level: lvl), &block) + self.log(msg, opts.merge( + level: lvl + ), &block) end define_method "#{name}?" do - return Resources::LOG_LEVELS[level] == lvl if level.is_a? Numeric + return Resources::LOG_LEVELS[self.level] == lvl if level.is_a? Numeric - level == lvl + self.level == lvl end end @@ -91,7 +97,9 @@ def clear end def <<(msg = nil, opts = {}) - log(msg, opts.merge(level: "")) + log(msg, opts.merge( + level: "" + )) end def add(*_arg) @@ -100,7 +108,9 @@ def add(*_arg) end def unknown(msg = nil, opts = {}) - log(msg, opts.merge(level: "UNKNOWN")) + log(msg, opts.merge( + level: "UNKNOWN" + )) end def datetime_format(*_arg) @@ -109,11 +119,15 @@ def datetime_format(*_arg) end def close - @client&.exitout + if !@client.nil? + @client.exitout + end end at_exit do - @client&.exitout + if !@client.nil? + @client.exitout + end end end end diff --git a/lib/logdna/client.rb b/lib/logdna/client.rb index ddb3ab7..b26434e 100755 --- a/lib/logdna/client.rb +++ b/lib/logdna/client.rb @@ -114,9 +114,12 @@ def send_request end def flush + if @lock.try_lock @flush_scheduled = false - send_request if @buffer.any? || @side_messages.any? + if @buffer.any? || @side_messages.any? + send_request + end @lock.unlock else schedule_flush diff --git a/lib/logdna/resources.rb b/lib/logdna/resources.rb index 8d9d91f..b1323c4 100755 --- a/lib/logdna/resources.rb +++ b/lib/logdna/resources.rb @@ -1,17 +1,15 @@ -# frozen_string_literal: true - module Resources - LOG_LEVELS = %w[DEBUG INFO WARN ERROR FATAL TRACE].freeze - DEFAULT_REQUEST_HEADER = { "Content-Type" => "application/json; charset=UTF-8" }.freeze - DEFAULT_REQUEST_TIMEOUT = 180_000 - MS_IN_A_DAY = 86_400_000 - MAX_REQUEST_TIMEOUT = 300_000 - MAX_LINE_LENGTH = 32_000 + LOG_LEVELS = ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'TRACE'].freeze + DEFAULT_REQUEST_HEADER = { 'Content-Type' => 'application/json; charset=UTF-8' }.freeze + DEFAULT_REQUEST_TIMEOUT = 180000 + MS_IN_A_DAY = 86400000 + MAX_REQUEST_TIMEOUT = 300000 + MAX_LINE_LENGTH = 32000 MAX_INPUT_LENGTH = 80 RETRY_TIMEOUT = 60 FLUSH_INTERVAL = 0.25 - FLUSH_BYTE_LIMIT = 500_000 - ENDPOINT = "https://logs.logdna.com/logs/ingest" - MAC_ADDR_CHECK = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/.freeze - IP_ADDR_CHECK = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.freeze + FLUSH_BYTE_LIMIT = 500000 + ENDPOINT = 'https://logs.logdna.com/logs/ingest'.freeze + MAC_ADDR_CHECK = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/ + IP_ADDR_CHECK = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ end diff --git a/lib/logdna/version.rb b/lib/logdna/version.rb index 363dd5c..944e6b7 100644 --- a/lib/logdna/version.rb +++ b/lib/logdna/version.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - module LogDNA - VERSION = "1.3.0" + VERSION = '1.3.0'.freeze end From 0fc59e821841807a0717e92e6270bfdd20d9a982 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 21:19:01 +0400 Subject: [PATCH 19/26] revert codebase back to the master --- Gemfile | 6 ++---- logdna.gemspec | 42 +++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 21 deletions(-) mode change 100755 => 100644 Gemfile mode change 100755 => 100644 logdna.gemspec diff --git a/Gemfile b/Gemfile old mode 100755 new mode 100644 index 18ca16e..bb242f2 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,4 @@ -# frozen_string_literal: true +source 'https://rubygems.org' -source "https://rubygems.org" - -# Specify your gem's dependencies in logdna.gemspec +# Specify your gem's dependencies in logdna_ruby.gemspec gemspec diff --git a/logdna.gemspec b/logdna.gemspec old mode 100755 new mode 100644 index d5be15f..1769c6e --- a/logdna.gemspec +++ b/logdna.gemspec @@ -1,23 +1,31 @@ -# frozen_string_literal: true - -lib = File.expand_path("lib", __dir__) +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "logdna/version" +require 'logdna/version' Gem::Specification.new do |spec| - spec.name = "logdna" + spec.name = 'logdna' spec.version = LogDNA::VERSION - spec.authors = "Gun Woo Choi, Derek Zhou, Vilya Levitskiy, Muaz Siddiqui" - spec.email = "support@logdna.com" - spec.summary = "LogDNA Ruby Logger" - spec.homepage = "https://github.com/logdna/ruby" - spec.license = "MIT" - spec.files = `git ls-files -z`.split("\x0").select { |f| f.match(/(.md|.rb|.gemspec|Gemfile|LICENSE)$/) } - spec.bindir = "exe" + spec.authors = 'Gun Woo Choi, Derek Zhou' + spec.email = 'support@logdna.com' + + spec.summary = 'LogDNA Ruby logger' + spec.homepage = 'https://github.com/logdna/ruby' + spec.license = 'MIT' + + spec.files = `git ls-files -z`.split("\x0").reject do |f| + f.match(%r{^(test|spec|features)/}) + end + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] - spec.add_runtime_dependency "concurrent-ruby", "~> 1.0" - spec.add_runtime_dependency "json", "~> 2.0" - spec.add_runtime_dependency "require_all", "~> 1.4" - spec.add_development_dependency "rubocop", "~> 0.77" + spec.require_paths = ['lib'] + + spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0' + spec.add_runtime_dependency 'require_all', '~> 1.4' + spec.add_runtime_dependency 'json', '~> 2.0' + + spec.add_development_dependency 'bundler', '~> 1.13' + spec.add_development_dependency 'rake', '~> 10.5' + spec.add_development_dependency 'rspec', '~> 3.5' + spec.add_development_dependency 'webmock', '~> 2.3' end From 507fb943768a62a81bc90950a32fd15d1b14705b Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 21:20:44 +0400 Subject: [PATCH 20/26] revert codebase back to the master --- Gemfile | 0 LICENSE | 0 lib/logdna/version.rb | 0 logdna.gemspec | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 Gemfile mode change 100644 => 100755 LICENSE mode change 100644 => 100755 lib/logdna/version.rb mode change 100644 => 100755 logdna.gemspec diff --git a/Gemfile b/Gemfile old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/lib/logdna/version.rb b/lib/logdna/version.rb old mode 100644 new mode 100755 diff --git a/logdna.gemspec b/logdna.gemspec old mode 100644 new mode 100755 From 47c10eb632e40a1f3eecd6ecaffe783f9bcfc66f Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 21:25:56 +0400 Subject: [PATCH 21/26] update gemspec --- logdna.gemspec | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/logdna.gemspec b/logdna.gemspec index 1769c6e..be05c27 100755 --- a/logdna.gemspec +++ b/logdna.gemspec @@ -6,26 +6,17 @@ require 'logdna/version' Gem::Specification.new do |spec| spec.name = 'logdna' spec.version = LogDNA::VERSION - spec.authors = 'Gun Woo Choi, Derek Zhou' + spec.authors = 'Gun Woo Choi, Derek Zhou, Vilya Levitskiy, Muaz Siddiqui' spec.email = 'support@logdna.com' - spec.summary = 'LogDNA Ruby logger' spec.homepage = 'https://github.com/logdna/ruby' spec.license = 'MIT' - - spec.files = `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{^(test|spec|features)/}) - end + spec.files = Dir.glob("{lib}/**/*.rb") + %w(LICENSE README.md) spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0' spec.add_runtime_dependency 'require_all', '~> 1.4' spec.add_runtime_dependency 'json', '~> 2.0' - - spec.add_development_dependency 'bundler', '~> 1.13' - spec.add_development_dependency 'rake', '~> 10.5' - spec.add_development_dependency 'rspec', '~> 3.5' - spec.add_development_dependency 'webmock', '~> 2.3' + spec.add_development_dependency 'rubocop', '~> 0.78' end From 9fe1bfda93cfc6aa3db7053f3e3ec6c3d090716c Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 23:10:20 +0400 Subject: [PATCH 22/26] change the environment from circleci/ruby:2.7.0 to circleci/ruby:2.7 --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8a79248..f7e5d60 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,14 +12,14 @@ test_build_filters: &test_build_filters jobs: test: docker: - - image: circleci/ruby:2.7.0 + - image: circleci/ruby:2.7 steps: - checkout - run: bundle install - run: rubocop -c .rubocop.yml -a build: docker: - - image: circleci/ruby:2.7.0 + - image: circleci/ruby:2.7 steps: - checkout - run: @@ -68,7 +68,7 @@ jobs: - ./logdna-*.gem publish: docker: - - image: circleci/ruby:2.7.0 + - image: circleci/ruby:2.7 steps: - attach_workspace: at: . From 6a55e832653d1c339d5bc6e1a71a99fb7dc2e77d Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 23:11:20 +0400 Subject: [PATCH 23/26] change the environment from circleci/ruby:2.7 to circleci/ruby:2.6.5 --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f7e5d60..69176ee 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,14 +12,14 @@ test_build_filters: &test_build_filters jobs: test: docker: - - image: circleci/ruby:2.7 + - image: circleci/ruby:2.6.5 steps: - checkout - run: bundle install - run: rubocop -c .rubocop.yml -a build: docker: - - image: circleci/ruby:2.7 + - image: circleci/ruby:2.6.5 steps: - checkout - run: @@ -68,7 +68,7 @@ jobs: - ./logdna-*.gem publish: docker: - - image: circleci/ruby:2.7 + - image: circleci/ruby:2.6.5 steps: - attach_workspace: at: . From d6397c72fcc2b0f69bc14360dcfe715ea905a3b2 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 23:18:26 +0400 Subject: [PATCH 24/26] use the .rubocop.yml from master --- .rubocop.yml | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e50c1ff..63b7ceb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,16 +56,18 @@ Style/CollectionMethods: # inject seems more common in the community. reduce: "inject" -Style/RedundantInterpolation: - Enabled: false +Style/UnneededInterpolation: + Enabled: flase Style/RescueStandardError: - Enabled: false + Enabled: flase # Either allow this style or don't. Marking it as safe with parenthesis # is silly. Let's try to live without them for now. Style/ParenthesesAroundCondition: AllowSafeAssignment: false +Lint/AssignmentInCondition: + AllowSafeAssignment: false # A specialized exception class will take one or more arguments and construct the message from it. # So both variants make sense. @@ -78,13 +80,10 @@ Style/RaiseArgs: Style/SignalException: EnforcedStyle: only_raise -Style/GuardClause: - Enabled: false - # Suppressing exceptions can be perfectly fine, and be it to avoid to # explicitly type nil into the rescue since that's what you want to return, # or suppressing LoadError for optional dependencies -Lint/SuppressedException: +Lint/HandleExceptions: Enabled: false # { ... } for multi-line blocks is okay, follow Weirichs rule instead: @@ -111,9 +110,6 @@ Style/SingleLineBlockParams: Lint/ShadowingOuterLocalVariable: Enabled: false -Lint/AssignmentInCondition: - Enabled: false - # Check with yard instead. Style/Documentation: Enabled: false @@ -126,28 +122,10 @@ Naming/BinaryOperatorParameterName: # also they'll fail CI anyway Lint/Debugger: Enabled: false -Lint/UnusedLocalVariable: - Enabled: true -Security/Eval: - Enabled: false + # Style preference Style/MethodDefParentheses: Enabled: false Style/TrailingCommaInHashLiteral: Enabled: false - -Style/IfUnlessModifier: - Enabled: false - -Lint/DuplicateMethods: - Enabled: false - -Style/RedundantSelf: - Enabled: false - -Style/NegatedIf: - Enabled: false - -Style/SafeNavigation: - Enabled: false From f7ed4fc27983ddedfb964eb9c6040405930c0875 Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 23:19:33 +0400 Subject: [PATCH 25/26] fix an issue in .rubocop.yml --- .rubocop.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 63b7ceb..39d3680 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -57,10 +57,10 @@ Style/CollectionMethods: reduce: "inject" Style/UnneededInterpolation: - Enabled: flase + Enabled: false Style/RescueStandardError: - Enabled: flase + Enabled: false # Either allow this style or don't. Marking it as safe with parenthesis # is silly. Let's try to live without them for now. From 830d14c640f3f0fff1417501f4a38d0616c5015d Mon Sep 17 00:00:00 2001 From: Samir Musali Date: Fri, 20 Dec 2019 23:20:55 +0400 Subject: [PATCH 26/26] fix deprecation issues in .rubocop.yml --- .rubocop.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 39d3680..bd8c31c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -56,7 +56,7 @@ Style/CollectionMethods: # inject seems more common in the community. reduce: "inject" -Style/UnneededInterpolation: +Style/RedundantInterpolation: Enabled: false Style/RescueStandardError: @@ -83,7 +83,7 @@ Style/SignalException: # Suppressing exceptions can be perfectly fine, and be it to avoid to # explicitly type nil into the rescue since that's what you want to return, # or suppressing LoadError for optional dependencies -Lint/HandleExceptions: +Lint/SuppressedException: Enabled: false # { ... } for multi-line blocks is okay, follow Weirichs rule instead: