semantic_logger 4.5.0 → 4.7.1
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/ansi_colors.rb +0 -10
- data/lib/semantic_logger/appender.rb +54 -64
- data/lib/semantic_logger/appender/async.rb +10 -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 +12 -11
- 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 +6 -5
- data/lib/semantic_logger/appender/splunk_http.rb +3 -3
- data/lib/semantic_logger/appender/syslog.rb +12 -12
- data/lib/semantic_logger/appender/tcp.rb +9 -9
- data/lib/semantic_logger/appender/udp.rb +2 -2
- data/lib/semantic_logger/appenders.rb +13 -34
- data/lib/semantic_logger/base.rb +43 -31
- data/lib/semantic_logger/formatters.rb +11 -11
- data/lib/semantic_logger/formatters/base.rb +15 -6
- data/lib/semantic_logger/formatters/color.rb +12 -13
- 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/raw.rb +39 -10
- data/lib/semantic_logger/formatters/signalfx.rb +14 -21
- 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 +49 -73
- 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 +37 -12
- data/lib/semantic_logger/subscriber.rb +14 -7
- 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 +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53de576d3dea3ae2099d237648a027026469632dda0f8c3840557c648ddb0626
|
4
|
+
data.tar.gz: a2fe41e466fd682cc536f33331698a74b19d9026cde7604db93f859e70686d25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9c53adbda24e55a427945f9c5953c6e53c244af0c00b4f81ba59c92c3e052d9f7306fc8941bbf0960d665757c56b4089bbc1214255fdfc5ec085fdda24b601e
|
7
|
+
data.tar.gz: 700143b4c0b34e347539b7b2fccd363683b45577a5520accd55a308175f92975ca041152ca03353f7e23ec71eb9189e6de54ff8f985eecf414d51b8900b2ad96
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ and are therefore not automatically included by this gem:
|
|
76
76
|
## V4 Upgrade notes
|
77
77
|
|
78
78
|
The following changes need to be made when upgrading to V4:
|
79
|
-
- Ruby V2.
|
79
|
+
- Ruby V2.3 / JRuby V9.1 is now the minimum runtime version.
|
80
80
|
- Replace calls to Logger#with_payload with SemanticLogger.named_tagged.
|
81
81
|
- Replace calls to Logger#payload with SemanticLogger.named_tags.
|
82
82
|
- MongoDB Appender requires Mongo Ruby Client V2 or greater.
|
data/Rakefile
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rake/clean"
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
|
-
$LOAD_PATH.unshift File.expand_path(
|
5
|
-
require
|
4
|
+
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
|
5
|
+
require "semantic_logger/version"
|
6
6
|
|
7
7
|
task :gem do
|
8
|
-
system
|
8
|
+
system "gem build semantic_logger.gemspec"
|
9
9
|
end
|
10
10
|
|
11
11
|
task publish: :gem do
|
12
12
|
system "git tag -a v#{SemanticLogger::VERSION} -m 'Tagging #{SemanticLogger::VERSION}'"
|
13
|
-
system
|
13
|
+
system "git push --tags"
|
14
14
|
system "gem push semantic_logger-#{SemanticLogger::VERSION}.gem"
|
15
15
|
system "rm semantic_logger-#{SemanticLogger::VERSION}.gem"
|
16
16
|
end
|
17
17
|
|
18
18
|
Rake::TestTask.new(:test) do |t|
|
19
|
-
t.pattern =
|
19
|
+
t.pattern = "test/**/*_test.rb"
|
20
20
|
t.verbose = true
|
21
21
|
t.warning = false
|
22
22
|
end
|
data/lib/semantic_logger.rb
CHANGED
@@ -1,43 +1,44 @@
|
|
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"
|
32
33
|
end
|
33
34
|
|
34
35
|
if defined?(JRuby)
|
35
36
|
module JRuby
|
36
|
-
autoload :GarbageCollectionLogger,
|
37
|
+
autoload :GarbageCollectionLogger, "semantic_logger/jruby/garbage_collection_logger"
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
|
-
require
|
41
|
+
require "semantic_logger/semantic_logger"
|
41
42
|
# @formatter:on
|
42
43
|
|
43
44
|
# Flush all appenders at exit, waiting for outstanding messages on the queue
|
@@ -11,15 +11,5 @@ module SemanticLogger
|
|
11
11
|
MAGENTA = "\e[35m".freeze
|
12
12
|
CYAN = "\e[36m".freeze
|
13
13
|
WHITE = "\e[37m".freeze
|
14
|
-
|
15
|
-
# DEPRECATED - NOT USED
|
16
|
-
LEVEL_MAP = {
|
17
|
-
trace: MAGENTA,
|
18
|
-
debug: GREEN,
|
19
|
-
info: CYAN,
|
20
|
-
warn: BOLD,
|
21
|
-
error: RED,
|
22
|
-
fatal: RED
|
23
|
-
}.freeze
|
24
14
|
end
|
25
15
|
end
|
@@ -1,93 +1,83 @@
|
|
1
1
|
module SemanticLogger
|
2
2
|
module Appender
|
3
3
|
# @formatter:off
|
4
|
-
autoload :Async,
|
5
|
-
autoload :AsyncBatch,
|
6
|
-
autoload :Bugsnag,
|
7
|
-
autoload :Elasticsearch,
|
8
|
-
autoload :ElasticsearchHttp,
|
9
|
-
autoload :File,
|
10
|
-
autoload :Graylog,
|
11
|
-
autoload :Honeybadger,
|
12
|
-
autoload :Kafka,
|
13
|
-
autoload :Sentry,
|
14
|
-
autoload :Http,
|
15
|
-
autoload :MongoDB,
|
16
|
-
autoload :NewRelic,
|
17
|
-
autoload :Rabbitmq,
|
18
|
-
autoload :Splunk,
|
19
|
-
autoload :SplunkHttp,
|
20
|
-
autoload :Syslog,
|
21
|
-
autoload :Tcp,
|
22
|
-
autoload :Udp,
|
23
|
-
autoload :Wrapper,
|
4
|
+
autoload :Async, "semantic_logger/appender/async"
|
5
|
+
autoload :AsyncBatch, "semantic_logger/appender/async_batch"
|
6
|
+
autoload :Bugsnag, "semantic_logger/appender/bugsnag"
|
7
|
+
autoload :Elasticsearch, "semantic_logger/appender/elasticsearch"
|
8
|
+
autoload :ElasticsearchHttp, "semantic_logger/appender/elasticsearch_http"
|
9
|
+
autoload :File, "semantic_logger/appender/file"
|
10
|
+
autoload :Graylog, "semantic_logger/appender/graylog"
|
11
|
+
autoload :Honeybadger, "semantic_logger/appender/honeybadger"
|
12
|
+
autoload :Kafka, "semantic_logger/appender/kafka"
|
13
|
+
autoload :Sentry, "semantic_logger/appender/sentry"
|
14
|
+
autoload :Http, "semantic_logger/appender/http"
|
15
|
+
autoload :MongoDB, "semantic_logger/appender/mongodb"
|
16
|
+
autoload :NewRelic, "semantic_logger/appender/new_relic"
|
17
|
+
autoload :Rabbitmq, "semantic_logger/appender/rabbitmq"
|
18
|
+
autoload :Splunk, "semantic_logger/appender/splunk"
|
19
|
+
autoload :SplunkHttp, "semantic_logger/appender/splunk_http"
|
20
|
+
autoload :Syslog, "semantic_logger/appender/syslog"
|
21
|
+
autoload :Tcp, "semantic_logger/appender/tcp"
|
22
|
+
autoload :Udp, "semantic_logger/appender/udp"
|
23
|
+
autoload :Wrapper, "semantic_logger/appender/wrapper"
|
24
24
|
# @formatter:on
|
25
25
|
|
26
|
-
# DEPRECATED, use SemanticLogger::AnsiColors
|
27
|
-
AnsiColors = SemanticLogger::AnsiColors
|
28
|
-
|
29
|
-
# DEPRECATED: use SemanticLogger::Formatters::Color.new
|
30
|
-
def self.colorized_formatter
|
31
|
-
SemanticLogger::Formatters::Color.new
|
32
|
-
end
|
33
|
-
|
34
|
-
# DEPRECATED: use SemanticLogger::Formatters::Json.new
|
35
|
-
def self.json_formatter
|
36
|
-
SemanticLogger::Formatters::Json.new
|
37
|
-
end
|
38
|
-
|
39
26
|
# Returns [SemanticLogger::Subscriber] appender for the supplied options
|
40
|
-
def self.factory(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
proxy_options = {}
|
47
|
-
ASYNC_OPTION_KEYS.each { |key| proxy_options[key] = options.delete(key) if options.key?(key) }
|
48
|
-
|
49
|
-
appender = build(options, &block)
|
27
|
+
def self.factory(async: false, batch: nil,
|
28
|
+
max_queue_size: 10_000, lag_check_interval: 1_000, lag_threshold_s: 30,
|
29
|
+
batch_size: 300, batch_seconds: 5,
|
30
|
+
**args,
|
31
|
+
&block)
|
32
|
+
appender = build(**args, &block)
|
50
33
|
|
51
34
|
# If appender implements #batch, then it should use the batch proxy by default.
|
52
|
-
batch
|
35
|
+
batch = true if batch.nil? && appender.respond_to?(:batch)
|
53
36
|
|
54
37
|
if batch == true
|
55
|
-
|
56
|
-
|
38
|
+
Appender::AsyncBatch.new(
|
39
|
+
appender: appender,
|
40
|
+
max_queue_size: max_queue_size,
|
41
|
+
lag_threshold_s: lag_threshold_s,
|
42
|
+
batch_size: batch_size,
|
43
|
+
batch_seconds: batch_seconds
|
44
|
+
)
|
57
45
|
elsif async == true
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
46
|
+
Appender::Async.new(
|
47
|
+
appender: appender,
|
48
|
+
max_queue_size: max_queue_size,
|
49
|
+
lag_check_interval: lag_check_interval,
|
50
|
+
lag_threshold_s: lag_threshold_s
|
51
|
+
)
|
62
52
|
else
|
63
53
|
appender
|
64
54
|
end
|
65
55
|
end
|
66
56
|
|
67
|
-
ASYNC_OPTION_KEYS = %i[max_queue_size lag_threshold_s batch_size batch_seconds lag_check_interval].freeze
|
68
|
-
|
69
57
|
# Returns [Subscriber] instance from the supplied options.
|
70
|
-
def self.build(
|
71
|
-
if
|
72
|
-
SemanticLogger::Appender::File.new(
|
73
|
-
elsif
|
58
|
+
def self.build(io: nil, file_name: nil, appender: nil, metric: nil, logger: nil, **args, &block)
|
59
|
+
if io || file_name
|
60
|
+
SemanticLogger::Appender::File.new(io: io, file_name: file_name, **args, &block)
|
61
|
+
elsif logger
|
62
|
+
SemanticLogger::Appender::Wrapper.new(logger: logger, **args, &block)
|
63
|
+
elsif appender
|
74
64
|
if appender.is_a?(Symbol)
|
75
|
-
SemanticLogger::Utils.constantize_symbol(appender).new(
|
65
|
+
SemanticLogger::Utils.constantize_symbol(appender).new(**args)
|
76
66
|
elsif appender.is_a?(Subscriber)
|
77
67
|
appender
|
78
68
|
else
|
79
69
|
raise(ArgumentError, "Parameter :appender must be either a Symbol or an object derived from SemanticLogger::Subscriber, not: #{appender.inspect}")
|
80
70
|
end
|
81
|
-
elsif
|
82
|
-
if
|
83
|
-
SemanticLogger::Utils.constantize_symbol(
|
84
|
-
elsif
|
85
|
-
|
71
|
+
elsif metric
|
72
|
+
if metric.is_a?(Symbol)
|
73
|
+
SemanticLogger::Utils.constantize_symbol(metric, "SemanticLogger::Metric").new(**args)
|
74
|
+
elsif metric.is_a?(Subscriber)
|
75
|
+
metric
|
86
76
|
else
|
87
77
|
raise(ArgumentError, "Parameter :metric must be either a Symbol or an object derived from SemanticLogger::Subscriber, not: #{appender.inspect}")
|
88
78
|
end
|
89
|
-
|
90
|
-
|
79
|
+
else
|
80
|
+
raise(ArgumentError, "To create an appender it must supply one of the following: :io, :file_name, :appender, :metric, or :logger")
|
91
81
|
end
|
92
82
|
end
|
93
83
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "forwardable"
|
2
2
|
|
3
3
|
module SemanticLogger
|
4
4
|
module Appender
|
@@ -15,6 +15,7 @@ module SemanticLogger
|
|
15
15
|
def_delegator :@appender, :filter
|
16
16
|
def_delegator :@appender, :host
|
17
17
|
def_delegator :@appender, :application
|
18
|
+
def_delegator :@appender, :environment
|
18
19
|
def_delegator :@appender, :level
|
19
20
|
def_delegator :@appender, :level=
|
20
21
|
def_delegator :@appender, :logger
|
@@ -72,6 +73,7 @@ module SemanticLogger
|
|
72
73
|
# Starts the worker thread if not running.
|
73
74
|
def thread
|
74
75
|
return @thread if @thread&.alive?
|
76
|
+
|
75
77
|
@thread = Thread.new { process }
|
76
78
|
end
|
77
79
|
|
@@ -114,21 +116,21 @@ module SemanticLogger
|
|
114
116
|
# This thread is designed to never go down unless the main thread terminates
|
115
117
|
# or the appender is closed.
|
116
118
|
Thread.current.name = logger.name
|
117
|
-
logger.trace
|
119
|
+
logger.trace "Async: Appender thread active"
|
118
120
|
begin
|
119
121
|
process_messages
|
120
|
-
rescue StandardError =>
|
122
|
+
rescue StandardError => e
|
121
123
|
# This block may be called after the file handles have been released by Ruby
|
122
124
|
begin
|
123
|
-
logger.error(
|
125
|
+
logger.error("Async: Restarting due to exception", e)
|
124
126
|
rescue StandardError
|
125
127
|
nil
|
126
128
|
end
|
127
129
|
retry
|
128
|
-
rescue Exception =>
|
130
|
+
rescue Exception => e
|
129
131
|
# This block may be called after the file handles have been released by Ruby
|
130
132
|
begin
|
131
|
-
logger.error(
|
133
|
+
logger.error("Async: Stopping due to fatal exception", e)
|
132
134
|
rescue StandardError
|
133
135
|
nil
|
134
136
|
end
|
@@ -136,7 +138,7 @@ module SemanticLogger
|
|
136
138
|
@thread = nil
|
137
139
|
# This block may be called after the file handles have been released by Ruby
|
138
140
|
begin
|
139
|
-
logger.trace(
|
141
|
+
logger.trace("Async: Thread has stopped")
|
140
142
|
rescue StandardError
|
141
143
|
nil
|
142
144
|
end
|
@@ -158,7 +160,7 @@ module SemanticLogger
|
|
158
160
|
break unless process_message(message)
|
159
161
|
end
|
160
162
|
end
|
161
|
-
logger.trace
|
163
|
+
logger.trace "Async: Queue Closed"
|
162
164
|
end
|
163
165
|
|
164
166
|
# Returns false when message processing should be stopped
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "concurrent"
|
2
2
|
|
3
3
|
module SemanticLogger
|
4
4
|
module Appender
|
@@ -42,7 +42,9 @@ module SemanticLogger
|
|
42
42
|
lag_threshold_s: lag_threshold_s
|
43
43
|
)
|
44
44
|
|
45
|
-
|
45
|
+
return if appender.respond_to?(:batch)
|
46
|
+
|
47
|
+
raise(ArgumentError, "#{appender.class.name} does not support batching. It must implement #batch")
|
46
48
|
end
|
47
49
|
|
48
50
|
# Add log message for processing.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "bugsnag"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem bugsnag is required for logging purposes. Please add the gem "bugsnag" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem bugsnag is required for logging purposes. Please add the gem "bugsnag" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
7
|
# Send log messages to Bugsnag
|
@@ -30,7 +30,7 @@ module SemanticLogger
|
|
30
30
|
# Proc: Only include log messages where the supplied Proc returns true
|
31
31
|
# The Proc must return true or false.
|
32
32
|
def initialize(level: :error, **args, &block)
|
33
|
-
raise
|
33
|
+
raise "Bugsnag only supports :info, :warn, or :error log levels" unless %i[info warn error fatal].include?(level)
|
34
34
|
|
35
35
|
# Replace the Bugsnag logger so that we can identify its log messages and not forward them to Bugsnag
|
36
36
|
::Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] }
|
@@ -51,7 +51,7 @@ module SemanticLogger
|
|
51
51
|
# Send an error notification to Bugsnag
|
52
52
|
def log(log)
|
53
53
|
# Ignore logs coming from Bugsnag itself
|
54
|
-
return false if log.name ==
|
54
|
+
return false if log.name == "Bugsnag"
|
55
55
|
|
56
56
|
# Send error messages as Runtime exceptions
|
57
57
|
exception =
|
@@ -77,11 +77,11 @@ module SemanticLogger
|
|
77
77
|
def log_level(log)
|
78
78
|
case log.level
|
79
79
|
when :error, :fatal
|
80
|
-
|
80
|
+
"error"
|
81
81
|
when :warn
|
82
|
-
|
82
|
+
"warning"
|
83
83
|
else
|
84
|
-
|
84
|
+
"info"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "elasticsearch"
|
3
3
|
rescue LoadError
|
4
|
-
raise 'Gem elasticsearch is required for logging to Elasticsearch. Please add the gem "elasticsearch" to your Gemfile.'
|
4
|
+
raise LoadError, 'Gem elasticsearch is required for logging to Elasticsearch. Please add the gem "elasticsearch" to your Gemfile.'
|
5
5
|
end
|
6
6
|
|
7
|
-
require
|
7
|
+
require "date"
|
8
8
|
|
9
9
|
# Forward all log messages to Elasticsearch.
|
10
10
|
#
|
@@ -123,14 +123,15 @@ module SemanticLogger
|
|
123
123
|
# send_get_body_as [String]
|
124
124
|
# Specify the HTTP method to use for GET requests with a body.
|
125
125
|
# Default: 'GET'
|
126
|
-
def initialize(url:
|
127
|
-
index:
|
128
|
-
date_pattern:
|
129
|
-
type:
|
126
|
+
def initialize(url: "http://localhost:9200",
|
127
|
+
index: "semantic_logger",
|
128
|
+
date_pattern: "%Y.%m.%d",
|
129
|
+
type: "log",
|
130
130
|
level: nil,
|
131
131
|
formatter: nil,
|
132
132
|
filter: nil,
|
133
133
|
application: nil,
|
134
|
+
environment: nil,
|
134
135
|
host: nil,
|
135
136
|
metrics: false,
|
136
137
|
**elasticsearch_args,
|
@@ -144,7 +145,7 @@ module SemanticLogger
|
|
144
145
|
@elasticsearch_args[:url] = url if url && !elasticsearch_args[:hosts]
|
145
146
|
@elasticsearch_args[:logger] = logger
|
146
147
|
|
147
|
-
super(level: level, formatter: formatter, filter: filter, application: application, host: host, metrics: false, &block)
|
148
|
+
super(level: level, formatter: formatter, filter: filter, application: application, environment: environment, host: host, metrics: false, &block)
|
148
149
|
reopen
|
149
150
|
end
|
150
151
|
|
@@ -173,15 +174,15 @@ module SemanticLogger
|
|
173
174
|
|
174
175
|
def write_to_elasticsearch(messages)
|
175
176
|
bulk_result = @client.bulk(body: messages)
|
176
|
-
return unless bulk_result[
|
177
|
+
return unless bulk_result["errors"]
|
177
178
|
|
178
|
-
failed = bulk_result[
|
179
|
+
failed = bulk_result["items"].reject { |x| x["status"] == 201 }
|
179
180
|
logger.error("ElasticSearch: Write failed. Messages discarded. : #{failed}")
|
180
181
|
end
|
181
182
|
|
182
183
|
def bulk_index(log)
|
183
184
|
expanded_index_name = log.time.strftime("#{index}-#{date_pattern}")
|
184
|
-
{
|
185
|
+
{"index" => {"_index" => expanded_index_name, "_type" => type}}
|
185
186
|
end
|
186
187
|
|
187
188
|
def default_formatter
|