From 89232551bcbb69243f2759b8137c08f64c22d170 Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Fri, 20 Dec 2019 16:50:54 -0800 Subject: [PATCH 1/6] rename the attribute and remove autocorrect from lints --- .rubocop.yml | 13 +++++++++++-- lib/logdna.rb | 12 ++++++------ lib/logdna/client.rb | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index deaad11..1015b95 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,7 +17,7 @@ Metrics/PerceivedComplexity: Max: 40 # Commonly used screens these days easily fit more than 80 characters. -Layout/LineLength: +Metrics/LineLength: Max: 120 # No space makes the method definition shorter and differentiates @@ -130,7 +130,7 @@ Style/IfUnlessModifier: Enabled: false Lint/DuplicateMethods: - Enabled: false + Enabled: true Style/RedundantSelf: Enabled: false @@ -140,3 +140,12 @@ Style/NegatedIf: Style/SafeNavigation: Enabled: false + +Style/FrozenStringLiteralComment: + Enabled: true + +Style/RedundantFreeze: + Enabled: true + +Style/MutableConstant: + Enabled: false diff --git a/lib/logdna.rb b/lib/logdna.rb index 4781277..86c9bb3 100755 --- a/lib/logdna.rb +++ b/lib/logdna.rb @@ -15,11 +15,11 @@ class Ruby < ::Logger # uncomment line below and line 3 to enforce singleton # include Singleton Logger::TRACE = 5 - attr_accessor :level, :app, :env, :meta + attr_accessor :log_level, :app, :env, :meta def initialize(key, opts = {}) @app = opts[:app] || "default" - @level = opts[:level] || "INFO" + @log_level = opts[:level] || "INFO" @env = opts[:env] @meta = opts[:meta] @internal_logger = Logger.new(STDOUT) @@ -46,7 +46,7 @@ def initialize(key, opts = {}) def default_opts { app: @app, - level: @level, + level: @log_level, env: @env, meta: @meta, } @@ -54,11 +54,11 @@ def default_opts def level=(value) if value.is_a? Numeric - @level = Resources::LOG_LEVELS[value] + @log_level = Resources::LOG_LEVELS[value] return end - @level = value + @log_level = value end def log(message = nil, opts = {}) @@ -93,7 +93,7 @@ def log(message = nil, opts = {}) def clear @app = "default" - @level = "INFO" + @log_level = "INFO" @env = nil @meta = nil end diff --git a/lib/logdna/client.rb b/lib/logdna/client.rb index 29290af..41c1e5a 100755 --- a/lib/logdna/client.rb +++ b/lib/logdna/client.rb @@ -99,6 +99,7 @@ def send_request ) do |http| http.request(@request) end + if @response.is_a?(Net::HTTPForbidden) @internal_logger.debug("Please provide a valid ingestion key") elsif !@response.is_a?(Net::HTTPSuccess) From 46efe7cd489a9ff15c583680407e8f53436adcac Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Fri, 20 Dec 2019 16:52:59 -0800 Subject: [PATCH 2/6] remove the automatically added freexes --- lib/logdna/client.rb | 1 - lib/logdna/resources.rb | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/logdna/client.rb b/lib/logdna/client.rb index 41c1e5a..29290af 100755 --- a/lib/logdna/client.rb +++ b/lib/logdna/client.rb @@ -99,7 +99,6 @@ def send_request ) do |http| http.request(@request) end - if @response.is_a?(Net::HTTPForbidden) @internal_logger.debug("Please provide a valid ingestion key") elsif !@response.is_a?(Net::HTTPSuccess) diff --git a/lib/logdna/resources.rb b/lib/logdna/resources.rb index 8d9d91f..eceb23b 100755 --- a/lib/logdna/resources.rb +++ b/lib/logdna/resources.rb @@ -1,8 +1,8 @@ # 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 + LOG_LEVELS = %w[DEBUG INFO WARN ERROR FATAL TRACE] + DEFAULT_REQUEST_HEADER = { "Content-Type" => "application/json; charset=UTF-8" } DEFAULT_REQUEST_TIMEOUT = 180_000 MS_IN_A_DAY = 86_400_000 MAX_REQUEST_TIMEOUT = 300_000 @@ -12,6 +12,6 @@ module Resources 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 + 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 From 1bc082d5672f1ee8e65da01150b3a72894609b00 Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Fri, 20 Dec 2019 17:49:56 -0800 Subject: [PATCH 3/6] remove log_level from accessors: --- lib/logdna.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logdna.rb b/lib/logdna.rb index 86c9bb3..411a40e 100755 --- a/lib/logdna.rb +++ b/lib/logdna.rb @@ -15,7 +15,7 @@ class Ruby < ::Logger # uncomment line below and line 3 to enforce singleton # include Singleton Logger::TRACE = 5 - attr_accessor :log_level, :app, :env, :meta + attr_accessor :app, :env, :meta def initialize(key, opts = {}) @app = opts[:app] || "default" From 463ba2a3a32306e4805dc50bdaae1fa7dfa5334c Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Thu, 2 Jan 2020 15:20:00 -0800 Subject: [PATCH 4/6] remove requirement --- .rubocop.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1015b95..40a7cf6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -146,6 +146,3 @@ Style/FrozenStringLiteralComment: Style/RedundantFreeze: Enabled: true - -Style/MutableConstant: - Enabled: false From d111e6f23bf124f1b0c23765c2917fe0ade4b081 Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Thu, 2 Jan 2020 15:23:49 -0800 Subject: [PATCH 5/6] edit rubocop --- .rubocop.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 40a7cf6..d9bdd21 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -140,9 +140,3 @@ Style/NegatedIf: Style/SafeNavigation: Enabled: false - -Style/FrozenStringLiteralComment: - Enabled: true - -Style/RedundantFreeze: - Enabled: true From 5a048fc258748242e11ab84978649011a877b283 Mon Sep 17 00:00:00 2001 From: vilyapilya <13.veter@gmail.com> Date: Thu, 2 Jan 2020 15:28:40 -0800 Subject: [PATCH 6/6] run rubocop -a --- .rubocop.yml | 2 +- lib/logdna/resources.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d9bdd21..c163530 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,7 +17,7 @@ Metrics/PerceivedComplexity: Max: 40 # Commonly used screens these days easily fit more than 80 characters. -Metrics/LineLength: +Layout/LineLength: Max: 120 # No space makes the method definition shorter and differentiates diff --git a/lib/logdna/resources.rb b/lib/logdna/resources.rb index eceb23b..8d9d91f 100755 --- a/lib/logdna/resources.rb +++ b/lib/logdna/resources.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Resources - LOG_LEVELS = %w[DEBUG INFO WARN ERROR FATAL TRACE] - DEFAULT_REQUEST_HEADER = { "Content-Type" => "application/json; charset=UTF-8" } + 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 @@ -12,6 +12,6 @@ module Resources 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])$/ - 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]?)$/ + 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