stackify-api-ruby 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e13cf81984bdf8a8f010af5a741a3d98e56cb5aff747c8dbc934c0a47edf1a5
4
- data.tar.gz: f4f69adfdde2a04c864440a8ca8dd3859529b4d397cbd26005dca9bd2aa1fea7
3
+ metadata.gz: 371cb99e1d47ff1680b37a4e4a8b69a992787ef047c3973e923bb08032486239
4
+ data.tar.gz: 379714698256d7614a12b1e07e996e5a0256f868df5db33e103ec136fd8eec01
5
5
  SHA512:
6
- metadata.gz: a27451afa0f62688c83977a9fb05f595689d0617d7c2d4f4e286c058d018e8eefe8051f03d4443dc27d3ebaaa35b0959ca281aa6205cf4e9dc777f259add3283
7
- data.tar.gz: 2827a27560393bee018e43c0055b7ef2a32baeb569e7df45f84313fea6cd8aef5b75c1d1a9d8e4d3ad2af0a81f0b068b44f57ef1d7b73a83a9a6af4769a10007
6
+ metadata.gz: f7aff04aee12c3a8346c39fb32f34965f360e969e960607053685c3081b2a27a333e4e7842d87f486d3ddb2341b49f18107276c96d8090d1b90e6ea258b766ab
7
+ data.tar.gz: 7e2d3a430f5794f6e29689255adc9be0dd36b4bddc9504507161c1a0d0edd4699bfa1df675c803f0bc1c4bd4090d2b080bf78886837f89f0b84d74e7f673f050
@@ -120,7 +120,7 @@ module Stackify
120
120
 
121
121
  def run
122
122
  Stackify::Utils.is_api_enabled
123
- Stackify.internal_log :info, "Stackify.run() transportType = #{Stackify.configuration.transport} | API version: #{Stackify::VERSION}"
123
+ Stackify.internal_log :info, "Stackify.run() transportType: #{Stackify.configuration.transport} | API version: #{Stackify::VERSION} | Ruby version: #{RUBY_VERSION}"
124
124
  if Stackify.configuration.api_enabled
125
125
  if Stackify.is_valid?
126
126
  # check transport types
@@ -11,7 +11,11 @@ module Stackify::Authorizable
11
11
  @@auth_client = nil
12
12
 
13
13
  def authorize attempts=3
14
- Stackify::EnvDetails.instance.set_rails_info
14
+ # Check if the ruby version is 2.0 we get the Rails info properties such as
15
+ # <Application root: e.g., /home/user/rails_app> which is required in authorization
16
+ if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.0')
17
+ Stackify::EnvDetails.instance.set_rails_info
18
+ end
15
19
  @@auth_lock.synchronize do
16
20
  return unless @@auth_client.nil?
17
21
  @@auth_client = Stackify::Authorizable::AuthorizationClient.new
@@ -4,7 +4,32 @@ module Stackify
4
4
 
5
5
  if Rails.version > '3.1'
6
6
  initializer 'Stackify set up of logger', group: :all do
7
+ if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('4.0')
8
+ # check if the client app is using the ActiveSupport::Logger
9
+ is_activesupport_logger = ::Rails.logger.is_a?(ActiveSupport::Logger)
10
+ elsif Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('3.0')
11
+ Stackify::Utils.check_buffered_logger
12
+ end
13
+
14
+ # Check if the log output is STDOUT
15
+ Stackify::Utils.check_log_output
16
+
17
+ # Proxy the client Rails logger and write logs to its default log_path.
18
+ # At the same time, we send the log messages to the LoggerClient.
7
19
  ::Rails.logger = ::Stackify::LoggerProxy.new ::Rails.logger
20
+
21
+ if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('6.0')
22
+ set_console_logs ::Rails.logger
23
+ elsif Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('4.0')
24
+ if is_activesupport_logger && Stackify.configuration.stdout_output
25
+ set_console_logs ::Rails.logger
26
+ end
27
+ # Another checking if the client app is using the default logger and not STDOUT
28
+ if Stackify.configuration.stdout_output == false
29
+ set_console_logs ::Rails.logger
30
+ end
31
+ end
32
+
8
33
  Stackify.run
9
34
  end
10
35
 
@@ -14,6 +39,16 @@ module Stackify
14
39
  end
15
40
  end
16
41
 
42
+ def set_console_logs logger
43
+ # Handle the stdout logs from Action Controller
44
+ ActionController::Base.logger = logger
45
+
46
+ # Handle the stdout logs from Action View
47
+ ActionView::Base.logger = logger
48
+
49
+ # Handle the stdout logs from Active Record
50
+ ActiveRecord::Base.logger = logger
51
+ end
17
52
  end
18
53
 
19
54
  end
@@ -12,7 +12,33 @@ module Stackify
12
12
  end
13
13
  end
14
14
 
15
- def log level, msg, call_trace
15
+ # This function is responsible in displaying log messages based on the level criteria
16
+ # @param num_level [Integer] level of the clients Rails.logger
17
+ # @param level [String] level coming from array of levels(debug info warn error fatal unknown) that we are going to filter with num_level
18
+ # So we filter all logs from num_level up to this level
19
+ # @param msg [Integer] log messages
20
+ # @param call_trace [Object] return the current execution stack
21
+ def log num_level, level, msg, call_trace
22
+ display_log = true
23
+ log_appender = false
24
+ buffer_log = false
25
+ if defined? Rails
26
+ display_log = false if Stackify.configuration.stdout_output
27
+ log_appender = true if defined?(Logging)
28
+ buffer_log = true if Stackify.configuration.buffered_logger
29
+ unless buffer_log
30
+ if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('4.0')
31
+ if display_log && log_appender
32
+ puts msg if num_level <= Logger.const_get(level.upcase).to_i
33
+ elsif display_log && log_appender == false
34
+ puts msg if num_level <= Logger.const_get(level.upcase).to_i
35
+ end
36
+ end
37
+ end
38
+ else
39
+ puts msg if num_level <= Logger.const_get(level.upcase).to_i
40
+ end
41
+
16
42
  return if @@transport.nil?
17
43
  task = log_message_task level, msg, call_trace
18
44
  @@transport.log level, msg, call_trace, task
@@ -1,14 +1,16 @@
1
+
1
2
  module Stackify
2
3
  class LoggerProxy < Object
3
4
 
4
5
  def initialize logger
5
- @logger = logger
6
- @logger.level = Logger.const_get(Stackify.configuration.log_level.to_s.upcase)
6
+ rails_logger = logger
7
+ num_level = logger.level
8
+ @logger = rails_logger
7
9
  %w(debug info warn error fatal unknown).each do |level|
8
10
  stackify_logger = if level == 'debug'
9
- -> (msg, caller) { Stackify.logger_client.log(level.downcase, msg, caller) unless msg.to_s.empty? }
11
+ -> (msg, caller) { Stackify.logger_client.log(num_level, level.downcase, msg, caller) unless msg.to_s.empty? }
10
12
  else
11
- -> (msg, caller) { Stackify.logger_client.log(level.downcase, msg, caller) }
13
+ -> (msg, caller) { Stackify.logger_client.log(num_level, level.downcase, msg, caller) }
12
14
  end
13
15
  LoggerProxy.class_eval do
14
16
  define_method level.to_sym do |*args , &block|
@@ -3,7 +3,7 @@ module Stackify
3
3
  class Configuration
4
4
 
5
5
  attr_accessor :api_key, :app_name, :app_location, :env, :log_level, :logger,
6
- :proxy, :mode, :base_api_url, :api_enabled, :transport, :errors, :http_endpoint
6
+ :proxy, :mode, :base_api_url, :api_enabled, :transport, :errors, :http_endpoint, :stdout_output, :buffered_logger
7
7
 
8
8
  attr_reader :send_interval, :flood_limit, :queue_max_size, :agent_log_url, :unix_socket_path, :http_endpoint
9
9
 
@@ -25,6 +25,8 @@ module Stackify
25
25
  @agent_log_url = '/log'
26
26
  @unix_socket_path = '/usr/local/stackify/stackify.sock'
27
27
  @http_endpoint = get_env 'STACKIFY_TRANSPORT_HTTP_ENDPOINT', 'https://localhost:10601'
28
+ @stdout_output = false
29
+ @buffered_logger = false
28
30
  end
29
31
 
30
32
  def get_env env_key, default
@@ -46,4 +46,29 @@ module Stackify::Utils
46
46
  'app_location' => Stackify.configuration.app_location || Dir.pwd
47
47
  }
48
48
  end
49
- end
49
+
50
+ # Check if the app is running on rails and the logger output is using STDOUT
51
+ def self.check_log_output
52
+ if defined? Rails
53
+ if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('5.0')
54
+ Stackify.configuration.stdout_output = ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT)
55
+ else
56
+ Stackify.configuration.stdout_output = self.logger_stdout
57
+ end
58
+ end
59
+ end
60
+
61
+ def self.logger_stdout
62
+ logdev = ::Rails.logger.instance_variable_get(:@logdev)
63
+ logger_source = logdev.dev if logdev.respond_to?(:dev)
64
+ sources = [$stdout]
65
+ found = sources.any? { |source| source == logger_source }
66
+ end
67
+
68
+ # Check if the rails version 3 and it's using the buffered logger
69
+ def self.check_buffered_logger
70
+ is_buffered_logger = false
71
+ is_buffered_logger = true if ::Rails.logger.is_a?(ActiveSupport::BufferedLogger)
72
+ Stackify.configuration.buffered_logger = is_buffered_logger
73
+ end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module Stackify
2
- VERSION = '1.2.7'
2
+ VERSION = '1.2.9'
3
3
  end
@@ -3,6 +3,14 @@ module Stackify
3
3
 
4
4
  def initialize name = 'LogsSender worker'
5
5
  super
6
+ case Stackify.configuration.transport
7
+ when Stackify::DEFAULT
8
+ name = 'LogsSender worker'
9
+ when Stackify::UNIX_SOCKET
10
+ name = 'UnixSocketSender worker'
11
+ when Stackify::AGENT_HTTP
12
+ name = 'AgentHTTPSender worker'
13
+ end
6
14
  @name = name
7
15
  @name += " ##{self.id}"
8
16
  @type = :logs_send
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler