semantic_logger 4.6.1 → 4.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -7
  3. data/lib/semantic_logger.rb +23 -22
  4. data/lib/semantic_logger/appender.rb +32 -33
  5. data/lib/semantic_logger/appender/async.rb +9 -8
  6. data/lib/semantic_logger/appender/async_batch.rb +4 -2
  7. data/lib/semantic_logger/appender/bugsnag.rb +43 -30
  8. data/lib/semantic_logger/appender/elasticsearch.rb +10 -10
  9. data/lib/semantic_logger/appender/elasticsearch_http.rb +4 -4
  10. data/lib/semantic_logger/appender/file.rb +2 -1
  11. data/lib/semantic_logger/appender/graylog.rb +12 -10
  12. data/lib/semantic_logger/appender/honeybadger.rb +3 -3
  13. data/lib/semantic_logger/appender/http.rb +20 -18
  14. data/lib/semantic_logger/appender/kafka.rb +5 -5
  15. data/lib/semantic_logger/appender/mongodb.rb +6 -6
  16. data/lib/semantic_logger/appender/new_relic.rb +2 -2
  17. data/lib/semantic_logger/appender/rabbitmq.rb +5 -5
  18. data/lib/semantic_logger/appender/sentry.rb +7 -7
  19. data/lib/semantic_logger/appender/splunk.rb +5 -5
  20. data/lib/semantic_logger/appender/splunk_http.rb +4 -4
  21. data/lib/semantic_logger/appender/syslog.rb +20 -14
  22. data/lib/semantic_logger/appender/tcp.rb +5 -5
  23. data/lib/semantic_logger/appender/udp.rb +2 -2
  24. data/lib/semantic_logger/appenders.rb +11 -11
  25. data/lib/semantic_logger/base.rb +52 -23
  26. data/lib/semantic_logger/formatters.rb +11 -11
  27. data/lib/semantic_logger/formatters/base.rb +8 -3
  28. data/lib/semantic_logger/formatters/color.rb +10 -6
  29. data/lib/semantic_logger/formatters/default.rb +18 -5
  30. data/lib/semantic_logger/formatters/fluentd.rb +3 -3
  31. data/lib/semantic_logger/formatters/json.rb +1 -1
  32. data/lib/semantic_logger/formatters/raw.rb +31 -7
  33. data/lib/semantic_logger/formatters/signalfx.rb +10 -9
  34. data/lib/semantic_logger/formatters/syslog.rb +7 -6
  35. data/lib/semantic_logger/formatters/syslog_cee.rb +7 -6
  36. data/lib/semantic_logger/jruby/garbage_collection_logger.rb +4 -2
  37. data/lib/semantic_logger/levels.rb +9 -7
  38. data/lib/semantic_logger/log.rb +52 -60
  39. data/lib/semantic_logger/logger.rb +6 -8
  40. data/lib/semantic_logger/metric/new_relic.rb +3 -3
  41. data/lib/semantic_logger/metric/signalfx.rb +3 -3
  42. data/lib/semantic_logger/metric/statsd.rb +7 -7
  43. data/lib/semantic_logger/processor.rb +7 -5
  44. data/lib/semantic_logger/reporters/minitest.rb +4 -4
  45. data/lib/semantic_logger/semantic_logger.rb +24 -11
  46. data/lib/semantic_logger/subscriber.rb +6 -5
  47. data/lib/semantic_logger/sync.rb +12 -0
  48. data/lib/semantic_logger/sync_processor.rb +43 -0
  49. data/lib/semantic_logger/utils.rb +6 -6
  50. data/lib/semantic_logger/version.rb +1 -1
  51. metadata +9 -7
@@ -1,8 +1,8 @@
1
- require 'uri'
1
+ require "uri"
2
2
  begin
3
- require 'statsd-ruby'
3
+ require "statsd-ruby"
4
4
  rescue LoadError
5
- raise LoadError.new('Gem statsd-ruby is required for logging metrics. Please add the gem "statsd-ruby" to your Gemfile.')
5
+ raise LoadError, 'Gem statsd-ruby is required for logging metrics. Please add the gem "statsd-ruby" to your Gemfile.'
6
6
  end
7
7
 
8
8
  module SemanticLogger
@@ -26,17 +26,17 @@ module SemanticLogger
26
26
  # metric: :statsd,
27
27
  # url: 'localhost:8125'
28
28
  # )
29
- def initialize(url: 'udp://localhost:8125')
29
+ def initialize(url: "udp://localhost:8125")
30
30
  @url = url
31
31
  end
32
32
 
33
33
  def reopen
34
34
  uri = URI.parse(@url)
35
- raise('Statsd only supports udp. Example: "udp://localhost:8125"') if uri.scheme != 'udp'
35
+ raise('Statsd only supports udp. Example: "udp://localhost:8125"') if uri.scheme != "udp"
36
36
 
37
37
  @statsd = ::Statsd.new(uri.host, uri.port)
38
- path = uri.path.chomp('/')
39
- @statsd.namespace = path.sub('/', '') if path != ''
38
+ path = uri.path.chomp("/")
39
+ @statsd.namespace = path.sub("/", "") if path != ""
40
40
  end
41
41
 
42
42
  def log(log)
@@ -13,11 +13,12 @@ module SemanticLogger
13
13
  # For example when an appender is not working etc..
14
14
  # By default logs to STDERR
15
15
  def self.logger
16
- @logger ||= begin
17
- l = SemanticLogger::Appender::File.new(io: STDERR, level: :warn)
18
- l.name = name
19
- l
20
- end
16
+ @logger ||=
17
+ begin
18
+ l = SemanticLogger::Appender::File.new(io: STDERR, level: :warn)
19
+ l.name = name
20
+ l
21
+ end
21
22
  end
22
23
 
23
24
  attr_reader :appenders
@@ -30,6 +31,7 @@ module SemanticLogger
30
31
  # Start the appender thread
31
32
  def start
32
33
  return false if active?
34
+
33
35
  thread
34
36
  true
35
37
  end
@@ -23,7 +23,7 @@ module SemanticLogger
23
23
  class Minitest < ::Minitest::AbstractReporter
24
24
  include SemanticLogger::Loggable
25
25
 
26
- logger.name = 'Minitest'
26
+ logger.name = "Minitest"
27
27
 
28
28
  attr_accessor :io
29
29
 
@@ -33,11 +33,11 @@ module SemanticLogger
33
33
 
34
34
  def after_test(test)
35
35
  if test.error?
36
- logger.benchmark_error("FAIL #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: 'minitest/fail')
36
+ logger.benchmark_error("FAIL #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: "minitest/fail")
37
37
  elsif test.skipped?
38
- logger.benchmark_warn("SKIP #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: 'minitest/skip')
38
+ logger.benchmark_warn("SKIP #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: "minitest/skip")
39
39
  else
40
- logger.benchmark_info("PASS #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: 'minitest/pass')
40
+ logger.benchmark_info("PASS #{test.class_name} #{test.name}", duration: test.time * 1_000, metric: "minitest/pass")
41
41
  end
42
42
  end
43
43
  end
@@ -1,5 +1,5 @@
1
- require 'concurrent'
2
- require 'socket'
1
+ require "concurrent"
2
+ require "socket"
3
3
 
4
4
  module SemanticLogger
5
5
  # Logging levels in order of most detailed to most severe
@@ -52,7 +52,7 @@ module SemanticLogger
52
52
  # Returns [String] name of this host for logging purposes
53
53
  # Note: Not all appenders use `host`
54
54
  def self.host
55
- @host ||= Socket.gethostname.force_encoding('UTF-8')
55
+ @host ||= Socket.gethostname.force_encoding("UTF-8")
56
56
  end
57
57
 
58
58
  # Override the default host name
@@ -82,8 +82,8 @@ module SemanticLogger
82
82
  @environment = environment
83
83
  end
84
84
 
85
- @application = ENV['SEMANTIC_LOGGER_APP'] || 'Semantic Logger'
86
- @environment = ENV['SEMANTIC_LOGGER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
85
+ @application = ENV["SEMANTIC_LOGGER_APP"] || "Semantic Logger"
86
+ @environment = ENV["SEMANTIC_LOGGER_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"]
87
87
 
88
88
  # Add a new logging appender as a new destination for all log messages
89
89
  # emitted from Semantic Logger
@@ -268,22 +268,23 @@ module SemanticLogger
268
268
  # Note:
269
269
  # To only register one of the signal handlers, set the other to nil
270
270
  # Set gc_log_microseconds to nil to not enable JRuby Garbage collections
271
- def self.add_signal_handler(log_level_signal = 'USR2', thread_dump_signal = 'TTIN', gc_log_microseconds = 100_000)
271
+ def self.add_signal_handler(log_level_signal = "USR2", thread_dump_signal = "TTIN", gc_log_microseconds = 100_000)
272
272
  if log_level_signal
273
273
  Signal.trap(log_level_signal) do
274
274
  index = default_level == :trace ? LEVELS.find_index(:error) : LEVELS.find_index(default_level)
275
275
  new_level = LEVELS[index - 1]
276
- self['SemanticLogger'].warn "Changed global default log level to #{new_level.inspect}"
276
+ self["SemanticLogger"].warn "Changed global default log level to #{new_level.inspect}"
277
277
  self.default_level = new_level
278
278
  end
279
279
  end
280
280
 
281
281
  if thread_dump_signal
282
282
  Signal.trap(thread_dump_signal) do
283
- logger = SemanticLogger['Thread Dump']
283
+ logger = SemanticLogger["Thread Dump"]
284
284
  Thread.list.each do |thread|
285
285
  # MRI re-uses the main thread for signals, JRuby uses `SIGTTIN handler` thread.
286
286
  next if defined?(JRuby) && (thread == Thread.current)
287
+
287
288
  logger.backtrace(thread: thread)
288
289
  end
289
290
  end
@@ -302,7 +303,7 @@ module SemanticLogger
302
303
  # If the tag being supplied is definitely a string then this fast
303
304
  # tag api can be used for short lived tags
304
305
  def self.fast_tag(tag)
305
- return yield if tag.nil? || tag == ''
306
+ return yield if tag.nil? || tag == ""
306
307
 
307
308
  t = Thread.current[:semantic_logger_tags] ||= []
308
309
  begin
@@ -379,7 +380,7 @@ module SemanticLogger
379
380
  # :nodoc
380
381
  def self.named_tagged(hash)
381
382
  return yield if hash.nil? || hash.empty?
382
- raise(ArgumentError, '#named_tagged only accepts named parameters (Hash)') unless hash.is_a?(Hash)
383
+ raise(ArgumentError, "#named_tagged only accepts named parameters (Hash)") unless hash.is_a?(Hash)
383
384
 
384
385
  begin
385
386
  push_named_tags(hash)
@@ -488,11 +489,23 @@ module SemanticLogger
488
489
  Thread.current[:semantic_logger_silence] || @default_level_index
489
490
  end
490
491
 
491
- private
492
+ # Run Semantic Logger in Synchronous mode.
493
+ #
494
+ # I.e. Instead of logging messages in a separate thread for better performance,
495
+ # log them using the current thread.
496
+ def self.sync!
497
+ @sync = true
498
+ end
499
+
500
+ # Running in synchronous mode?
501
+ def self.sync?
502
+ @sync
503
+ end
492
504
 
493
505
  # Initial default Level for all new instances of SemanticLogger::Logger
494
506
  @default_level = :info
495
507
  @default_level_index = Levels.index(@default_level)
496
508
  @backtrace_level = :error
497
509
  @backtrace_level_index = Levels.index(@backtrace_level)
510
+ @sync = false
498
511
  end
@@ -45,11 +45,12 @@ module SemanticLogger
45
45
  # Give each appender its own logger for logging.
46
46
  # For example trace messages sent to services or errors when something fails.
47
47
  def logger
48
- @logger ||= begin
49
- logger = SemanticLogger::Processor.logger.clone
50
- logger.name = self.class.name
51
- logger
52
- end
48
+ @logger ||=
49
+ begin
50
+ logger = SemanticLogger::Processor.logger.clone
51
+ logger.name = self.class.name
52
+ logger
53
+ end
53
54
  end
54
55
 
55
56
  # Set the formatter from Symbol|Hash|Block
@@ -0,0 +1,12 @@
1
+ # Run Semantic Logger in Synchronous mode.
2
+ #
3
+ # I.e. Instead of logging messages in a separate thread for better performance,
4
+ # log them using the current thread.
5
+ #
6
+ # Usage:
7
+ # require "semantic_logger/sync"
8
+ #
9
+ # Or, when using a Gemfile:
10
+ # gem "semantic_logger", require: "semantic_logger/sync"
11
+ require "semantic_logger"
12
+ SemanticLogger.sync!
@@ -0,0 +1,43 @@
1
+ module SemanticLogger
2
+ # Thread that submits and processes log requests
3
+ class SyncProcessor
4
+ extend Forwardable
5
+
6
+ # Forward methods that can be called directly
7
+ def_delegator :@appenders, :add
8
+ def_delegator :@appenders, :log
9
+ def_delegator :@appenders, :flush
10
+ def_delegator :@appenders, :close
11
+ def_delegator :@appenders, :reopen
12
+
13
+ # Allow the internal logger to be overridden from its default of STDERR
14
+ # Can be replaced with another Ruby logger or Rails logger, but never to
15
+ # SemanticLogger::Logger itself since it is for reporting problems
16
+ # while trying to log to the various appenders
17
+ class << self
18
+ attr_writer :logger
19
+ end
20
+
21
+ # Internal logger for SemanticLogger
22
+ # For example when an appender is not working etc..
23
+ # By default logs to STDERR
24
+ def self.logger
25
+ @logger ||=
26
+ begin
27
+ l = SemanticLogger::Appender::File.new(io: STDERR, level: :warn)
28
+ l.name = name
29
+ l
30
+ end
31
+ end
32
+
33
+ attr_reader :appenders
34
+
35
+ def initialize
36
+ @appenders = Appenders.new(self.class.logger.dup)
37
+ end
38
+
39
+ def start
40
+ # NOP
41
+ end
42
+ end
43
+ end
@@ -2,7 +2,7 @@ module SemanticLogger
2
2
  # Internal-use only utility functions for Semantic Logger.
3
3
  # Not intended for public use.
4
4
  module Utils
5
- def self.constantize_symbol(symbol, namespace = 'SemanticLogger::Appender')
5
+ def self.constantize_symbol(symbol, namespace = "SemanticLogger::Appender")
6
6
  klass = "#{namespace}::#{camelize(symbol.to_s)}"
7
7
  begin
8
8
  Object.const_get(klass)
@@ -15,8 +15,8 @@ module SemanticLogger
15
15
  def self.camelize(term)
16
16
  string = term.to_s
17
17
  string = string.sub(/^[a-z\d]*/, &:capitalize)
18
- string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
19
- string.gsub!('/'.freeze, '::'.freeze)
18
+ string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
19
+ string.gsub!("/".freeze, "::".freeze)
20
20
  string
21
21
  end
22
22
 
@@ -32,7 +32,7 @@ module SemanticLogger
32
32
  end
33
33
  end
34
34
 
35
- SELF_PATTERN = File.join('lib', 'semantic_logger')
35
+ SELF_PATTERN = File.join("lib", "semantic_logger")
36
36
 
37
37
  # Extract the backtrace leaving out the last few Semantic Logger lines.
38
38
  def self.extract_backtrace(stack = caller)
@@ -50,11 +50,11 @@ module SemanticLogger
50
50
  stack
51
51
  end
52
52
 
53
- GEM_ROOT = File.expand_path('../../..', __dir__) + '/'
53
+ GEM_ROOT = File.expand_path("../../..", __dir__) + "/"
54
54
 
55
55
  def self.system_path?(path)
56
56
  path.start_with?(GEM_ROOT) ||
57
- path.start_with?(RbConfig::CONFIG['rubylibdir'])
57
+ path.start_with?(RbConfig::CONFIG["rubylibdir"])
58
58
  end
59
59
  end
60
60
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger
2
- VERSION = '4.6.1'.freeze
2
+ VERSION = "4.7.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.1
4
+ version: 4.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-24 00:00:00.000000000 Z
11
+ date: 2020-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- description:
27
+ description:
28
28
  email:
29
29
  - reidmo@gmail.com
30
30
  executables: []
@@ -85,13 +85,15 @@ files:
85
85
  - lib/semantic_logger/reporters/minitest.rb
86
86
  - lib/semantic_logger/semantic_logger.rb
87
87
  - lib/semantic_logger/subscriber.rb
88
+ - lib/semantic_logger/sync.rb
89
+ - lib/semantic_logger/sync_processor.rb
88
90
  - lib/semantic_logger/utils.rb
89
91
  - lib/semantic_logger/version.rb
90
92
  homepage: https://github.com/rocketjob/semantic_logger
91
93
  licenses:
92
94
  - Apache-2.0
93
95
  metadata: {}
94
- post_install_message:
96
+ post_install_message:
95
97
  rdoc_options: []
96
98
  require_paths:
97
99
  - lib
@@ -106,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  - !ruby/object:Gem::Version
107
109
  version: '0'
108
110
  requirements: []
109
- rubygems_version: 3.0.6
110
- signing_key:
111
+ rubygems_version: 3.1.4
112
+ signing_key:
111
113
  specification_version: 4
112
114
  summary: Feature rich logging framework, and replacement for existing Ruby & Rails
113
115
  loggers.