semantic_logger 4.5.0 → 4.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -21
- data/Rakefile +7 -7
- data/lib/semantic_logger/ansi_colors.rb +0 -10
- data/lib/semantic_logger/appender/async.rb +12 -10
- data/lib/semantic_logger/appender/async_batch.rb +7 -3
- data/lib/semantic_logger/appender/bugsnag.rb +43 -30
- data/lib/semantic_logger/appender/elasticsearch.rb +34 -15
- data/lib/semantic_logger/appender/elasticsearch_http.rb +4 -4
- data/lib/semantic_logger/appender/file.rb +249 -67
- 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 +41 -20
- data/lib/semantic_logger/appender/io.rb +68 -0
- data/lib/semantic_logger/appender/kafka.rb +46 -31
- 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/sentry_ruby.rb +138 -0
- data/lib/semantic_logger/appender/splunk.rb +7 -5
- data/lib/semantic_logger/appender/splunk_http.rb +6 -5
- data/lib/semantic_logger/appender/syslog.rb +23 -15
- data/lib/semantic_logger/appender/tcp.rb +9 -9
- data/lib/semantic_logger/appender/udp.rb +2 -2
- data/lib/semantic_logger/appender/wrapper.rb +3 -2
- data/lib/semantic_logger/appender.rb +62 -65
- data/lib/semantic_logger/appenders.rb +36 -53
- data/lib/semantic_logger/base.rb +61 -39
- data/lib/semantic_logger/formatters/base.rb +16 -6
- data/lib/semantic_logger/formatters/color.rb +14 -15
- data/lib/semantic_logger/formatters/default.rb +18 -5
- data/lib/semantic_logger/formatters/fluentd.rb +7 -18
- data/lib/semantic_logger/formatters/json.rb +3 -5
- data/lib/semantic_logger/formatters/logfmt.rb +77 -0
- data/lib/semantic_logger/formatters/raw.rb +39 -10
- data/lib/semantic_logger/formatters/signalfx.rb +14 -21
- data/lib/semantic_logger/formatters/syslog.rb +8 -6
- data/lib/semantic_logger/formatters/syslog_cee.rb +9 -7
- data/lib/semantic_logger/formatters.rb +13 -13
- 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 +58 -73
- data/lib/semantic_logger/loggable.rb +8 -1
- data/lib/semantic_logger/logger.rb +19 -11
- 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 +9 -7
- data/lib/semantic_logger/reporters/minitest.rb +4 -4
- data/lib/semantic_logger/semantic_logger.rb +57 -23
- data/lib/semantic_logger/subscriber.rb +24 -7
- data/lib/semantic_logger/sync.rb +12 -0
- data/lib/semantic_logger/sync_processor.rb +58 -0
- data/lib/semantic_logger/test/capture_log_events.rb +34 -0
- data/lib/semantic_logger/utils.rb +32 -13
- data/lib/semantic_logger/version.rb +1 -1
- data/lib/semantic_logger.rb +27 -22
- metadata +15 -10
@@ -5,7 +5,7 @@ module SemanticLogger
|
|
5
5
|
class Subscriber < SemanticLogger::Base
|
6
6
|
# Every appender has its own formatter
|
7
7
|
attr_reader :formatter
|
8
|
-
attr_writer :application, :host, :logger, :metrics
|
8
|
+
attr_writer :application, :environment, :host, :logger, :metrics
|
9
9
|
|
10
10
|
# Returns the current log level if set, otherwise it logs everything it receives.
|
11
11
|
def level
|
@@ -22,6 +22,11 @@ module SemanticLogger
|
|
22
22
|
# NOOP
|
23
23
|
end
|
24
24
|
|
25
|
+
# Method called to log an event
|
26
|
+
def log(log)
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
|
25
30
|
# Returns [SemanticLogger::Formatters::Default] default formatter for this subscriber.
|
26
31
|
def default_formatter
|
27
32
|
SemanticLogger::Formatters::Default.new
|
@@ -32,6 +37,11 @@ module SemanticLogger
|
|
32
37
|
@application || SemanticLogger.application
|
33
38
|
end
|
34
39
|
|
40
|
+
# Allow environment name to be set globally or on a per subscriber basis.
|
41
|
+
def environment
|
42
|
+
@environment || SemanticLogger.environment
|
43
|
+
end
|
44
|
+
|
35
45
|
# Allow host name to be set globally or on a per subscriber basis.
|
36
46
|
def host
|
37
47
|
@host || SemanticLogger.host
|
@@ -40,11 +50,12 @@ module SemanticLogger
|
|
40
50
|
# Give each appender its own logger for logging.
|
41
51
|
# For example trace messages sent to services or errors when something fails.
|
42
52
|
def logger
|
43
|
-
@logger ||=
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
@logger ||=
|
54
|
+
begin
|
55
|
+
logger = SemanticLogger::Processor.logger.clone
|
56
|
+
logger.name = self.class.name
|
57
|
+
logger
|
58
|
+
end
|
48
59
|
end
|
49
60
|
|
50
61
|
# Set the formatter from Symbol|Hash|Block
|
@@ -62,6 +73,11 @@ module SemanticLogger
|
|
62
73
|
super(log) && (log.metric_only? ? metrics? : true)
|
63
74
|
end
|
64
75
|
|
76
|
+
# Whether this appender is logging to stdout or stderror
|
77
|
+
def console_output?
|
78
|
+
false
|
79
|
+
end
|
80
|
+
|
65
81
|
private
|
66
82
|
|
67
83
|
# Initializer for Abstract Class SemanticLogger::Subscriber
|
@@ -92,9 +108,10 @@ module SemanticLogger
|
|
92
108
|
# metrics: [Boolean]
|
93
109
|
# Whether to log metric only entries with this subscriber.
|
94
110
|
# Default: false
|
95
|
-
def initialize(level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false, &block)
|
111
|
+
def initialize(level: nil, formatter: nil, filter: nil, application: nil, environment: nil, host: nil, metrics: false, &block)
|
96
112
|
self.formatter = block || formatter
|
97
113
|
@application = application
|
114
|
+
@environment = environment
|
98
115
|
@host = host
|
99
116
|
@metrics = metrics
|
100
117
|
|
@@ -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,58 @@
|
|
1
|
+
module SemanticLogger
|
2
|
+
# The SyncProcessor performs logging in the current thread.
|
3
|
+
#
|
4
|
+
# Appenders are designed to only be used by one thread at a time, so all calls
|
5
|
+
# are mutex protected in case SyncProcessor is being used in a multi-threaded environment.
|
6
|
+
class SyncProcessor
|
7
|
+
def add(*args, &block)
|
8
|
+
@mutex.synchronize { @appenders.add(*args, &block) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def log(*args, &block)
|
12
|
+
@mutex.synchronize { @appenders.log(*args, &block) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def flush
|
16
|
+
@mutex.synchronize { @appenders.flush }
|
17
|
+
end
|
18
|
+
|
19
|
+
def close
|
20
|
+
@mutex.synchronize { @appenders.close }
|
21
|
+
end
|
22
|
+
|
23
|
+
def reopen(*args)
|
24
|
+
@mutex.synchronize { @appenders.reopen(*args) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Allow the internal logger to be overridden from its default of $stderr
|
28
|
+
# Can be replaced with another Ruby logger or Rails logger, but never to
|
29
|
+
# SemanticLogger::Logger itself since it is for reporting problems
|
30
|
+
# while trying to log to the various appenders
|
31
|
+
class << self
|
32
|
+
attr_writer :logger
|
33
|
+
end
|
34
|
+
|
35
|
+
# Internal logger for SemanticLogger
|
36
|
+
# For example when an appender is not working etc..
|
37
|
+
# By default logs to $stderr
|
38
|
+
def self.logger
|
39
|
+
@logger ||=
|
40
|
+
begin
|
41
|
+
l = SemanticLogger::Appender::IO.new($stderr, level: :warn)
|
42
|
+
l.name = name
|
43
|
+
l
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
attr_reader :appenders
|
48
|
+
|
49
|
+
def initialize(appenders = nil)
|
50
|
+
@mutex = Mutex.new
|
51
|
+
@appenders = appenders || Appenders.new(self.class.logger.dup)
|
52
|
+
end
|
53
|
+
|
54
|
+
def start
|
55
|
+
# NOP
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SemanticLogger
|
2
|
+
module Test
|
3
|
+
# Logging class to captures all logging events in memory.
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
#
|
7
|
+
# class UserTest < ActiveSupport::TestCase
|
8
|
+
# describe User do
|
9
|
+
# let(:capture_logger) { SemanticLogger::Test::CaptureLogEvents.new }
|
10
|
+
# let(:user) { User.new }
|
11
|
+
#
|
12
|
+
# it "logs message" do
|
13
|
+
# user.stub(:logger, capture_logger) do
|
14
|
+
# user.enable!
|
15
|
+
# end
|
16
|
+
# assert_equal "Hello World", capture_logger.events.last.message
|
17
|
+
# assert_equal :info, capture_logger.events.last.level
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
class CaptureLogEvents < SemanticLogger::Subscriber
|
22
|
+
attr_accessor :events
|
23
|
+
|
24
|
+
# By default collect all log levels, and collect metric only log events.
|
25
|
+
def initialize(level: :trace, metrics: true)
|
26
|
+
super(level: level, metrics: true)
|
27
|
+
end
|
28
|
+
|
29
|
+
def log(log)
|
30
|
+
(@events ||= []) << log
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
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,29 +32,48 @@ module SemanticLogger
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
# Extract the backtrace leaving out the last few Semantic Logger lines.
|
35
|
+
# Extract the backtrace stripping off the leading semantic logger entries.
|
36
|
+
# Leaves all other system and gem path entries in place.
|
38
37
|
def self.extract_backtrace(stack = caller)
|
39
|
-
while (first = stack.first) &&
|
38
|
+
while (first = stack.first) && extract_path?(first)
|
40
39
|
stack.shift
|
41
40
|
end
|
42
41
|
stack
|
43
42
|
end
|
44
43
|
|
45
|
-
|
44
|
+
def self.extract_paths
|
45
|
+
@extract_paths ||= %w[lib/semantic_logger lib/rails_semantic_logger]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Whether this path should be excluded from any cleansed backtrace
|
49
|
+
def self.extract_path?(path)
|
50
|
+
extract_paths.any? { |exclude| path.include?(exclude) }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Try to strip everything off of the supplied backtrace, until the first application stack entry is at the top.
|
54
|
+
# For example all leading gem paths and built-in ruby code paths are removed from the top.
|
55
|
+
# Once the first application entry is found, the remaining stack is returned.
|
46
56
|
def self.strip_backtrace(stack = caller)
|
47
|
-
while (first = stack.first) &&
|
57
|
+
while (first = stack.first) && (strip_path?(first) || extract_path?(first))
|
48
58
|
stack.shift
|
49
59
|
end
|
50
60
|
stack
|
51
61
|
end
|
52
62
|
|
53
|
-
|
63
|
+
# Paths to exclude in the stripped backtrace
|
64
|
+
# Includes Gems and built-in Ruby code paths
|
65
|
+
def self.strip_paths
|
66
|
+
@strip_paths ||=
|
67
|
+
begin
|
68
|
+
paths = Gem.path | [Gem.default_dir]
|
69
|
+
paths << RbConfig::CONFIG["rubylibdir"]
|
70
|
+
paths
|
71
|
+
end
|
72
|
+
end
|
54
73
|
|
55
|
-
|
56
|
-
|
57
|
-
|
74
|
+
# Whether this path should be excluded from any cleansed backtrace
|
75
|
+
def self.strip_path?(path)
|
76
|
+
strip_paths.any? { |exclude| path.start_with?(exclude) }
|
58
77
|
end
|
59
78
|
end
|
60
79
|
end
|
data/lib/semantic_logger.rb
CHANGED
@@ -1,43 +1,48 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "semantic_logger/core_ext/thread"
|
2
|
+
require "semantic_logger/version"
|
3
3
|
|
4
4
|
# @formatter:off
|
5
5
|
module SemanticLogger
|
6
|
-
autoload :AnsiColors,
|
7
|
-
autoload :Appender,
|
8
|
-
autoload :Appenders,
|
9
|
-
autoload :Base,
|
10
|
-
autoload :DebugAsTraceLogger,
|
11
|
-
autoload :Formatters,
|
12
|
-
autoload :Levels,
|
13
|
-
autoload :Log,
|
14
|
-
autoload :Logger,
|
15
|
-
autoload :Loggable,
|
16
|
-
autoload :Processor,
|
17
|
-
autoload :Subscriber,
|
18
|
-
autoload :
|
6
|
+
autoload :AnsiColors, "semantic_logger/ansi_colors"
|
7
|
+
autoload :Appender, "semantic_logger/appender"
|
8
|
+
autoload :Appenders, "semantic_logger/appenders"
|
9
|
+
autoload :Base, "semantic_logger/base"
|
10
|
+
autoload :DebugAsTraceLogger, "semantic_logger/debug_as_trace_logger"
|
11
|
+
autoload :Formatters, "semantic_logger/formatters"
|
12
|
+
autoload :Levels, "semantic_logger/levels"
|
13
|
+
autoload :Log, "semantic_logger/log"
|
14
|
+
autoload :Logger, "semantic_logger/logger"
|
15
|
+
autoload :Loggable, "semantic_logger/loggable"
|
16
|
+
autoload :Processor, "semantic_logger/processor"
|
17
|
+
autoload :Subscriber, "semantic_logger/subscriber"
|
18
|
+
autoload :SyncProcessor, "semantic_logger/sync_processor"
|
19
|
+
autoload :Utils, "semantic_logger/utils"
|
19
20
|
|
20
21
|
module Concerns
|
21
|
-
autoload :Compatibility,
|
22
|
+
autoload :Compatibility, "semantic_logger/concerns/compatibility"
|
22
23
|
end
|
23
24
|
|
24
25
|
module Metric
|
25
|
-
autoload :NewRelic,
|
26
|
-
autoload :Signalfx,
|
27
|
-
autoload :Statsd,
|
26
|
+
autoload :NewRelic, "semantic_logger/metric/new_relic"
|
27
|
+
autoload :Signalfx, "semantic_logger/metric/signalfx"
|
28
|
+
autoload :Statsd, "semantic_logger/metric/statsd"
|
28
29
|
end
|
29
30
|
|
30
31
|
module Reporters
|
31
|
-
autoload :Minitest,
|
32
|
+
autoload :Minitest, "semantic_logger/reporters/minitest"
|
33
|
+
end
|
34
|
+
|
35
|
+
module Test
|
36
|
+
autoload :CaptureLogEvents, "semantic_logger/test/capture_log_events"
|
32
37
|
end
|
33
38
|
|
34
39
|
if defined?(JRuby)
|
35
40
|
module JRuby
|
36
|
-
autoload :GarbageCollectionLogger,
|
41
|
+
autoload :GarbageCollectionLogger, "semantic_logger/jruby/garbage_collection_logger"
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
40
|
-
require
|
45
|
+
require "semantic_logger/semantic_logger"
|
41
46
|
# @formatter:on
|
42
47
|
|
43
48
|
# Flush all appenders at exit, waiting for outstanding messages on the queue
|
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.12.0
|
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:
|
11
|
+
date: 2022-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,9 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
|
-
- reidmo@gmail.com
|
30
29
|
executables: []
|
31
30
|
extensions: []
|
32
31
|
extra_rdoc_files: []
|
@@ -46,11 +45,13 @@ files:
|
|
46
45
|
- lib/semantic_logger/appender/graylog.rb
|
47
46
|
- lib/semantic_logger/appender/honeybadger.rb
|
48
47
|
- lib/semantic_logger/appender/http.rb
|
48
|
+
- lib/semantic_logger/appender/io.rb
|
49
49
|
- lib/semantic_logger/appender/kafka.rb
|
50
50
|
- lib/semantic_logger/appender/mongodb.rb
|
51
51
|
- lib/semantic_logger/appender/new_relic.rb
|
52
52
|
- lib/semantic_logger/appender/rabbitmq.rb
|
53
53
|
- lib/semantic_logger/appender/sentry.rb
|
54
|
+
- lib/semantic_logger/appender/sentry_ruby.rb
|
54
55
|
- lib/semantic_logger/appender/splunk.rb
|
55
56
|
- lib/semantic_logger/appender/splunk_http.rb
|
56
57
|
- lib/semantic_logger/appender/syslog.rb
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- lib/semantic_logger/formatters/default.rb
|
69
70
|
- lib/semantic_logger/formatters/fluentd.rb
|
70
71
|
- lib/semantic_logger/formatters/json.rb
|
72
|
+
- lib/semantic_logger/formatters/logfmt.rb
|
71
73
|
- lib/semantic_logger/formatters/one_line.rb
|
72
74
|
- lib/semantic_logger/formatters/raw.rb
|
73
75
|
- lib/semantic_logger/formatters/signalfx.rb
|
@@ -85,13 +87,16 @@ files:
|
|
85
87
|
- lib/semantic_logger/reporters/minitest.rb
|
86
88
|
- lib/semantic_logger/semantic_logger.rb
|
87
89
|
- lib/semantic_logger/subscriber.rb
|
90
|
+
- lib/semantic_logger/sync.rb
|
91
|
+
- lib/semantic_logger/sync_processor.rb
|
92
|
+
- lib/semantic_logger/test/capture_log_events.rb
|
88
93
|
- lib/semantic_logger/utils.rb
|
89
94
|
- lib/semantic_logger/version.rb
|
90
|
-
homepage: https://
|
95
|
+
homepage: https://logger.rocketjob.io
|
91
96
|
licenses:
|
92
97
|
- Apache-2.0
|
93
98
|
metadata: {}
|
94
|
-
post_install_message:
|
99
|
+
post_install_message:
|
95
100
|
rdoc_options: []
|
96
101
|
require_paths:
|
97
102
|
- lib
|
@@ -99,15 +104,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
104
|
requirements:
|
100
105
|
- - ">="
|
101
106
|
- !ruby/object:Gem::Version
|
102
|
-
version: '2.
|
107
|
+
version: '2.5'
|
103
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
109
|
requirements:
|
105
110
|
- - ">="
|
106
111
|
- !ruby/object:Gem::Version
|
107
112
|
version: '0'
|
108
113
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
110
|
-
signing_key:
|
114
|
+
rubygems_version: 3.2.33
|
115
|
+
signing_key:
|
111
116
|
specification_version: 4
|
112
117
|
summary: Feature rich logging framework, and replacement for existing Ruby & Rails
|
113
118
|
loggers.
|