semantic_logger 4.6.1 → 4.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -7
- data/lib/semantic_logger.rb +23 -22
- data/lib/semantic_logger/appender.rb +32 -33
- data/lib/semantic_logger/appender/async.rb +9 -8
- data/lib/semantic_logger/appender/async_batch.rb +4 -2
- data/lib/semantic_logger/appender/bugsnag.rb +7 -7
- data/lib/semantic_logger/appender/elasticsearch.rb +10 -10
- data/lib/semantic_logger/appender/elasticsearch_http.rb +4 -4
- data/lib/semantic_logger/appender/file.rb +2 -1
- data/lib/semantic_logger/appender/graylog.rb +12 -10
- data/lib/semantic_logger/appender/honeybadger.rb +3 -3
- data/lib/semantic_logger/appender/http.rb +20 -18
- data/lib/semantic_logger/appender/kafka.rb +5 -5
- data/lib/semantic_logger/appender/mongodb.rb +6 -6
- data/lib/semantic_logger/appender/new_relic.rb +2 -2
- data/lib/semantic_logger/appender/rabbitmq.rb +5 -5
- data/lib/semantic_logger/appender/sentry.rb +7 -7
- data/lib/semantic_logger/appender/splunk.rb +5 -5
- data/lib/semantic_logger/appender/splunk_http.rb +2 -2
- data/lib/semantic_logger/appender/syslog.rb +12 -12
- data/lib/semantic_logger/appender/tcp.rb +5 -5
- data/lib/semantic_logger/appender/udp.rb +2 -2
- data/lib/semantic_logger/appenders.rb +11 -11
- data/lib/semantic_logger/base.rb +16 -14
- data/lib/semantic_logger/formatters.rb +11 -11
- data/lib/semantic_logger/formatters/base.rb +8 -3
- data/lib/semantic_logger/formatters/color.rb +1 -1
- data/lib/semantic_logger/formatters/default.rb +18 -5
- data/lib/semantic_logger/formatters/fluentd.rb +3 -3
- data/lib/semantic_logger/formatters/json.rb +1 -1
- data/lib/semantic_logger/formatters/raw.rb +30 -6
- data/lib/semantic_logger/formatters/signalfx.rb +10 -9
- data/lib/semantic_logger/formatters/syslog.rb +3 -3
- data/lib/semantic_logger/formatters/syslog_cee.rb +3 -3
- data/lib/semantic_logger/jruby/garbage_collection_logger.rb +4 -2
- data/lib/semantic_logger/levels.rb +9 -7
- data/lib/semantic_logger/log.rb +17 -11
- data/lib/semantic_logger/logger.rb +6 -6
- data/lib/semantic_logger/metric/new_relic.rb +3 -3
- data/lib/semantic_logger/metric/signalfx.rb +3 -3
- data/lib/semantic_logger/metric/statsd.rb +7 -7
- data/lib/semantic_logger/processor.rb +7 -5
- data/lib/semantic_logger/reporters/minitest.rb +4 -4
- data/lib/semantic_logger/semantic_logger.rb +25 -10
- data/lib/semantic_logger/subscriber.rb +6 -5
- data/lib/semantic_logger/sync.rb +12 -0
- data/lib/semantic_logger/sync_processor.rb +44 -0
- data/lib/semantic_logger/utils.rb +6 -6
- data/lib/semantic_logger/version.rb +1 -1
- metadata +4 -2
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "concurrent"
|
2
2
|
module SemanticLogger
|
3
3
|
# Logger stores the class name to be used for all log messages so that every
|
4
4
|
# log message written by this instance will include the class name
|
@@ -9,7 +9,7 @@ module SemanticLogger
|
|
9
9
|
subscriber = block || object
|
10
10
|
|
11
11
|
unless subscriber.is_a?(Proc) || subscriber.respond_to?(:call)
|
12
|
-
raise(
|
12
|
+
raise("When supplying an on_log subscriber, it must support the #call method")
|
13
13
|
end
|
14
14
|
|
15
15
|
subscribers = (@subscribers ||= Concurrent::Array.new)
|
@@ -21,7 +21,7 @@ module SemanticLogger
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.processor
|
24
|
-
@processor
|
24
|
+
@processor ||= SemanticLogger.sync? ? SyncProcessor.new : Processor.new
|
25
25
|
end
|
26
26
|
|
27
27
|
# Returns a Logger instance
|
@@ -65,7 +65,7 @@ module SemanticLogger
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
-
@processor =
|
68
|
+
@processor = nil
|
69
69
|
@subscribers = nil
|
70
70
|
|
71
71
|
def self.call_subscribers(log)
|
@@ -74,8 +74,8 @@ module SemanticLogger
|
|
74
74
|
@subscribers.each do |subscriber|
|
75
75
|
begin
|
76
76
|
subscriber.call(log)
|
77
|
-
rescue Exception =>
|
78
|
-
self.class.processor.logger.error(
|
77
|
+
rescue Exception => e
|
78
|
+
self.class.processor.logger.error("Exception calling :on_log subscriber", e)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "newrelic_rpm"
|
3
3
|
rescue LoadError
|
4
|
-
raise LoadError
|
4
|
+
raise LoadError, 'Gem newrelic_rpm is required for logging to New Relic. Please add the gem "newrelic_rpm" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# Send Metrics to NewRelic
|
@@ -37,7 +37,7 @@ module SemanticLogger
|
|
37
37
|
# regular expression. All other messages will be ignored.
|
38
38
|
# Proc: Only include log messages where the supplied Proc returns true
|
39
39
|
# The Proc must return true or false.
|
40
|
-
def initialize(prefix:
|
40
|
+
def initialize(prefix: "Custom", **args, &block)
|
41
41
|
@prefix = prefix
|
42
42
|
super(**args, &block)
|
43
43
|
end
|
@@ -10,7 +10,7 @@ module SemanticLogger
|
|
10
10
|
class Signalfx < SemanticLogger::Appender::Http
|
11
11
|
attr_reader :full_url
|
12
12
|
|
13
|
-
END_POINT =
|
13
|
+
END_POINT = "v2/datapoint".freeze
|
14
14
|
|
15
15
|
# Create SignalFx metrics appender.
|
16
16
|
#
|
@@ -75,7 +75,7 @@ module SemanticLogger
|
|
75
75
|
# end
|
76
76
|
def initialize(token:,
|
77
77
|
dimensions: nil,
|
78
|
-
url:
|
78
|
+
url: "https://ingest.signalfx.com",
|
79
79
|
formatter: nil,
|
80
80
|
**args,
|
81
81
|
&block)
|
@@ -84,7 +84,7 @@ module SemanticLogger
|
|
84
84
|
|
85
85
|
super(url: url, formatter: formatter, **args, &block)
|
86
86
|
|
87
|
-
@header[
|
87
|
+
@header["X-SF-TOKEN"] = token
|
88
88
|
@full_url = "#{url}/#{END_POINT}"
|
89
89
|
end
|
90
90
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "uri"
|
2
2
|
begin
|
3
|
-
require
|
3
|
+
require "statsd-ruby"
|
4
4
|
rescue LoadError
|
5
|
-
raise LoadError
|
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:
|
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 !=
|
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(
|
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 ||=
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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 =
|
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:
|
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:
|
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:
|
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
|
2
|
-
require
|
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(
|
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[
|
86
|
-
@environment = 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 =
|
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[
|
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[
|
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,
|
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,6 +489,19 @@ module SemanticLogger
|
|
488
489
|
Thread.current[:semantic_logger_silence] || @default_level_index
|
489
490
|
end
|
490
491
|
|
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
|
504
|
+
|
491
505
|
private
|
492
506
|
|
493
507
|
# Initial default Level for all new instances of SemanticLogger::Logger
|
@@ -495,4 +509,5 @@ module SemanticLogger
|
|
495
509
|
@default_level_index = Levels.index(@default_level)
|
496
510
|
@backtrace_level = :error
|
497
511
|
@backtrace_level_index = Levels.index(@backtrace_level)
|
512
|
+
@synchronous = false
|
498
513
|
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 ||=
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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,44 @@
|
|
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
|
+
|
43
|
+
end
|
44
|
+
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 =
|
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!(
|
19
|
-
string.gsub!(
|
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(
|
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(
|
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[
|
57
|
+
path.start_with?(RbConfig::CONFIG["rubylibdir"])
|
58
58
|
end
|
59
59
|
end
|
60
60
|
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.
|
4
|
+
version: 4.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -85,6 +85,8 @@ 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
|