semantic_logger 4.6.0.beta1 → 4.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- 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 +15 -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 +3 -4
- data/lib/semantic_logger/appender/syslog.rb +20 -14
- 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 +42 -18
- data/lib/semantic_logger/formatters.rb +11 -11
- data/lib/semantic_logger/formatters/base.rb +8 -3
- data/lib/semantic_logger/formatters/color.rb +10 -6
- 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 +31 -7
- data/lib/semantic_logger/formatters/signalfx.rb +10 -9
- data/lib/semantic_logger/formatters/syslog.rb +7 -6
- data/lib/semantic_logger/formatters/syslog_cee.rb +7 -6
- 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 +52 -60
- data/lib/semantic_logger/logger.rb +6 -8
- 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 +24 -11
- data/lib/semantic_logger/subscriber.rb +6 -5
- data/lib/semantic_logger/sync.rb +12 -0
- data/lib/semantic_logger/sync_processor.rb +43 -0
- data/lib/semantic_logger/utils.rb +6 -6
- data/lib/semantic_logger/version.rb +1 -1
- metadata +7 -5
@@ -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,11 +489,23 @@ module SemanticLogger
|
|
488
489
|
Thread.current[:semantic_logger_silence] || @default_level_index
|
489
490
|
end
|
490
491
|
|
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
|
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 ||=
|
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,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 =
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-04 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
|
@@ -102,11 +104,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
104
|
version: '2.3'
|
103
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
106
|
requirements:
|
105
|
-
- - "
|
107
|
+
- - ">="
|
106
108
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
109
|
+
version: '0'
|
108
110
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.1.2
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: Feature rich logging framework, and replacement for existing Ruby & Rails
|