semantic_logger 4.2.0 → 4.2.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 +3 -3
- data/Rakefile +1 -1
- data/lib/semantic_logger/ansi_colors.rb +11 -12
- data/lib/semantic_logger/appender.rb +4 -5
- data/lib/semantic_logger/appender/async.rb +24 -16
- data/lib/semantic_logger/appender/async_batch.rb +1 -4
- data/lib/semantic_logger/appender/bugsnag.rb +67 -63
- data/lib/semantic_logger/appender/elasticsearch.rb +154 -157
- data/lib/semantic_logger/appender/elasticsearch_http.rb +59 -55
- data/lib/semantic_logger/appender/file.rb +1 -3
- data/lib/semantic_logger/appender/graylog.rb +114 -110
- data/lib/semantic_logger/appender/honeybadger.rb +54 -51
- data/lib/semantic_logger/appender/http.rb +194 -190
- data/lib/semantic_logger/appender/kafka.rb +152 -149
- data/lib/semantic_logger/appender/mongodb.rb +3 -3
- data/lib/semantic_logger/appender/new_relic.rb +52 -49
- data/lib/semantic_logger/appender/sentry.rb +59 -54
- data/lib/semantic_logger/appender/splunk.rb +108 -103
- data/lib/semantic_logger/appender/splunk_http.rb +82 -79
- data/lib/semantic_logger/appender/syslog.rb +4 -5
- data/lib/semantic_logger/appender/tcp.rb +8 -29
- data/lib/semantic_logger/appender/udp.rb +2 -3
- data/lib/semantic_logger/appender/wrapper.rb +2 -2
- data/lib/semantic_logger/base.rb +18 -16
- data/lib/semantic_logger/concerns/compatibility.rb +0 -1
- data/lib/semantic_logger/core_ext/thread.rb +0 -1
- data/lib/semantic_logger/formatters.rb +3 -5
- data/lib/semantic_logger/formatters/base.rb +2 -3
- data/lib/semantic_logger/formatters/color.rb +29 -12
- data/lib/semantic_logger/formatters/default.rb +10 -10
- data/lib/semantic_logger/formatters/json.rb +0 -2
- data/lib/semantic_logger/formatters/one_line.rb +2 -2
- data/lib/semantic_logger/formatters/raw.rb +7 -10
- data/lib/semantic_logger/formatters/signalfx.rb +3 -5
- data/lib/semantic_logger/formatters/syslog.rb +2 -3
- data/lib/semantic_logger/formatters/syslog_cee.rb +2 -3
- data/lib/semantic_logger/jruby/garbage_collection_logger.rb +8 -5
- data/lib/semantic_logger/log.rb +17 -17
- data/lib/semantic_logger/loggable.rb +6 -9
- data/lib/semantic_logger/logger.rb +0 -1
- data/lib/semantic_logger/metric/new_relic.rb +58 -55
- data/lib/semantic_logger/metric/signalfx.rb +108 -106
- data/lib/semantic_logger/metric/statsd.rb +2 -3
- data/lib/semantic_logger/processor.rb +9 -9
- data/lib/semantic_logger/semantic_logger.rb +50 -30
- data/lib/semantic_logger/subscriber.rb +0 -1
- data/lib/semantic_logger/utils.rb +37 -37
- data/lib/semantic_logger/version.rb +2 -2
- data/test/appender/async_batch_test.rb +0 -1
- data/test/appender/async_test.rb +0 -1
- data/test/appender/bugsnag_test.rb +7 -8
- data/test/appender/elasticsearch_http_test.rb +5 -6
- data/test/appender/elasticsearch_test.rb +14 -10
- data/test/appender/file_test.rb +5 -6
- data/test/appender/graylog_test.rb +8 -8
- data/test/appender/honeybadger_test.rb +6 -7
- data/test/appender/http_test.rb +4 -5
- data/test/appender/kafka_test.rb +5 -6
- data/test/appender/mongodb_test.rb +11 -13
- data/test/appender/new_relic_test.rb +8 -9
- data/test/appender/newrelic_rpm.rb +1 -1
- data/test/appender/sentry_test.rb +7 -8
- data/test/appender/splunk_http_test.rb +4 -4
- data/test/appender/splunk_test.rb +1 -3
- data/test/appender/syslog_test.rb +3 -5
- data/test/appender/tcp_test.rb +4 -5
- data/test/appender/udp_test.rb +4 -5
- data/test/appender/wrapper_test.rb +2 -3
- data/test/concerns/compatibility_test.rb +0 -1
- data/test/debug_as_trace_logger_test.rb +0 -1
- data/test/formatters/color_test.rb +5 -6
- data/test/formatters/default_test.rb +16 -17
- data/test/formatters/one_line_test.rb +1 -2
- data/test/formatters/signalfx_test.rb +8 -11
- data/test/formatters_test.rb +3 -3
- data/test/in_memory_appender.rb +0 -1
- data/test/in_memory_appender_helper.rb +1 -1
- data/test/in_memory_batch_appender.rb +0 -1
- data/test/in_memory_metrics_appender.rb +0 -1
- data/test/loggable_test.rb +2 -3
- data/test/logger_test.rb +11 -14
- data/test/measure_test.rb +13 -15
- data/test/metric/new_relic_test.rb +2 -3
- data/test/metric/signalfx_test.rb +4 -5
- data/test/semantic_logger_test.rb +28 -3
- data/test/test_helper.rb +6 -7
- metadata +34 -34
@@ -103,7 +103,7 @@ module SemanticLogger
|
|
103
103
|
# application: [String]
|
104
104
|
# Name of this application to appear in log messages.
|
105
105
|
# Default: SemanticLogger.application
|
106
|
-
def initialize(uri:, collection_name: 'semantic_logger', write_concern: 0, collection_size: 1024**3, collection_max: nil,
|
106
|
+
def initialize(uri:, collection_name: 'semantic_logger', write_concern: 0, collection_size: 1024 ** 3, collection_max: nil,
|
107
107
|
level: nil, formatter: nil, filter: nil, host: nil, application: nil, &block)
|
108
108
|
|
109
109
|
@client = Mongo::Client.new(uri, logger: logger)
|
@@ -144,10 +144,10 @@ module SemanticLogger
|
|
144
144
|
begin
|
145
145
|
@collection.create
|
146
146
|
rescue Mongo::Error::OperationFailure
|
147
|
-
|
147
|
+
nil
|
148
148
|
end
|
149
149
|
|
150
|
-
@collection.indexes.create_one(
|
150
|
+
@collection.indexes.create_one(tags: 1)
|
151
151
|
end
|
152
152
|
|
153
153
|
# Purge all data from the capped collection by dropping the collection
|
@@ -11,58 +11,61 @@ end
|
|
11
11
|
#
|
12
12
|
# Example:
|
13
13
|
# SemanticLogger.add_appender(appender: :new_relic)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
14
|
+
module SemanticLogger
|
15
|
+
module Appender
|
16
|
+
class NewRelic < SemanticLogger::Subscriber
|
17
|
+
# Create Appender
|
18
|
+
#
|
19
|
+
# Parameters
|
20
|
+
# level: [:trace | :debug | :info | :warn | :error | :fatal]
|
21
|
+
# Override the log level for this appender.
|
22
|
+
# Default: :error
|
23
|
+
#
|
24
|
+
# formatter: [Object|Proc]
|
25
|
+
# An instance of a class that implements #call, or a Proc to be used to format
|
26
|
+
# the output from this appender
|
27
|
+
# Default: Use the built-in formatter (See: #call)
|
28
|
+
#
|
29
|
+
# filter: [Regexp|Proc]
|
30
|
+
# RegExp: Only include log messages where the class name matches the supplied.
|
31
|
+
# regular expression. All other messages will be ignored.
|
32
|
+
# Proc: Only include log messages where the supplied Proc returns true
|
33
|
+
# The Proc must return true or false.
|
34
|
+
def initialize(level: :error,
|
35
|
+
formatter: nil,
|
36
|
+
filter: nil,
|
37
|
+
application: nil,
|
38
|
+
host: nil,
|
39
|
+
&block)
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
# Returns [Hash] of parameters to send to New Relic.
|
45
|
+
def call(log, logger)
|
46
|
+
h = SemanticLogger::Formatters::Raw.new.call(log, logger)
|
47
|
+
h.delete(:time)
|
48
|
+
h.delete(:exception)
|
49
|
+
{metric: log.metric, custom_params: h}
|
50
|
+
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
# Send an error notification to New Relic
|
53
|
+
def log(log)
|
54
|
+
# Send error messages as Runtime exceptions
|
55
|
+
exception =
|
56
|
+
if log.exception
|
57
|
+
log.exception
|
58
|
+
else
|
59
|
+
error = RuntimeError.new(log.message)
|
60
|
+
error.set_backtrace(log.backtrace) if log.backtrace
|
61
|
+
error
|
62
|
+
end
|
63
|
+
# For more documentation on the NewRelic::Agent.notice_error method see:
|
64
|
+
# http://rubydoc.info/github/newrelic/rpm/NewRelic/Agent#notice_error-instance_method
|
65
|
+
# and https://docs.newrelic.com/docs/ruby/ruby-agent-api
|
66
|
+
::NewRelic::Agent.notice_error(exception, formatter.call(log, self))
|
67
|
+
true
|
60
68
|
end
|
61
|
-
|
62
|
-
# http://rubydoc.info/github/newrelic/rpm/NewRelic/Agent#notice_error-instance_method
|
63
|
-
# and https://docs.newrelic.com/docs/ruby/ruby-agent-api
|
64
|
-
NewRelic::Agent.notice_error(exception, formatter.call(log, self))
|
65
|
-
true
|
69
|
+
end
|
66
70
|
end
|
67
|
-
|
68
71
|
end
|
@@ -9,63 +9,68 @@ end
|
|
9
9
|
# Example:
|
10
10
|
# SemanticLogger.add_appender(appender: :sentry)
|
11
11
|
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
12
|
+
module SemanticLogger
|
13
|
+
module Appender
|
14
|
+
class Sentry < SemanticLogger::Subscriber
|
15
|
+
# Create Appender
|
16
|
+
#
|
17
|
+
# Parameters
|
18
|
+
# level: [:trace | :debug | :info | :warn | :error | :fatal]
|
19
|
+
# Override the log level for this appender.
|
20
|
+
# Default: :error
|
21
|
+
#
|
22
|
+
# formatter: [Object|Proc|Symbol|Hash]
|
23
|
+
# An instance of a class that implements #call, or a Proc to be used to format
|
24
|
+
# the output from this appender
|
25
|
+
# Default: Use the built-in formatter (See: #call)
|
26
|
+
#
|
27
|
+
# filter: [Regexp|Proc]
|
28
|
+
# RegExp: Only include log messages where the class name matches the supplied.
|
29
|
+
# regular expression. All other messages will be ignored.
|
30
|
+
# Proc: Only include log messages where the supplied Proc returns true
|
31
|
+
# The Proc must return true or false.
|
32
|
+
#
|
33
|
+
# host: [String]
|
34
|
+
# Name of this host to appear in log messages.
|
35
|
+
# Default: SemanticLogger.host
|
36
|
+
#
|
37
|
+
# application: [String]
|
38
|
+
# Name of this application to appear in log messages.
|
39
|
+
# Default: SemanticLogger.application
|
40
|
+
def initialize(level: :error, formatter: nil, filter: nil, application: nil, host: nil, &block)
|
41
|
+
# Replace the Sentry Raven logger so that we can identify its log messages and not forward them to Sentry
|
42
|
+
Raven.configure { |config| config.logger = SemanticLogger[Raven] }
|
43
|
+
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
# Send an error notification to sentry
|
47
|
+
def log(log)
|
48
|
+
# Ignore logs coming from Raven itself
|
49
|
+
return false if log.name == 'Raven'
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
context = formatter.call(log, self)
|
52
|
+
attrs = {
|
53
|
+
level: context.delete(:level),
|
54
|
+
user: context.delete(:user),
|
55
|
+
tags: context.delete(:tags),
|
56
|
+
extra: context
|
57
|
+
}
|
58
|
+
if log.exception
|
59
|
+
context.delete(:exception)
|
60
|
+
Raven.capture_exception(log.exception, attrs)
|
61
|
+
else
|
62
|
+
attrs[:extra][:backtrace] = log.backtrace if log.backtrace
|
63
|
+
Raven.capture_message(context[:message], attrs)
|
64
|
+
end
|
65
|
+
true
|
66
|
+
end
|
63
67
|
|
64
|
-
|
68
|
+
private
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
# Use Raw Formatter by default
|
71
|
+
def default_formatter
|
72
|
+
SemanticLogger::Formatters::Raw.new
|
73
|
+
end
|
74
|
+
end
|
69
75
|
end
|
70
|
-
|
71
76
|
end
|
@@ -18,114 +18,119 @@ end
|
|
18
18
|
# scheme: :https,
|
19
19
|
# index: 'main'
|
20
20
|
# )
|
21
|
-
|
22
|
-
|
21
|
+
module SemanticLogger
|
22
|
+
module Appender
|
23
|
+
class Splunk < SemanticLogger::Subscriber
|
24
|
+
attr_reader :config, :index, :service, :service_index, :source_type
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
26
|
+
# Write to Splunk.
|
27
|
+
#
|
28
|
+
# Parameters
|
29
|
+
# :username [String]
|
30
|
+
# User name to log into splunk with.
|
31
|
+
# Not required if :token has been supplied.
|
32
|
+
#
|
33
|
+
# :password [String]
|
34
|
+
# Password to log into splunk with.
|
35
|
+
# Not required if :token has been supplied.
|
36
|
+
#
|
37
|
+
# :token
|
38
|
+
# Supply a preauthenticated Splunk token instead of username and password.
|
39
|
+
# Not required if username and password are supplied.
|
40
|
+
#
|
41
|
+
# :host [String]
|
42
|
+
# Splunk server host name.
|
43
|
+
# Default: 'localhost'
|
44
|
+
#
|
45
|
+
# :port [Integer]
|
46
|
+
# The Splunk management port.
|
47
|
+
# Default: 8089
|
48
|
+
#
|
49
|
+
# :scheme [Symbol]
|
50
|
+
# Either :https or :http
|
51
|
+
# Default: :https
|
52
|
+
#
|
53
|
+
# :index [String]
|
54
|
+
# Splunk index to use.
|
55
|
+
# Default: 'main'
|
56
|
+
#
|
57
|
+
# :namespace [Namespace]
|
58
|
+
# Application namespace instance.
|
59
|
+
#
|
60
|
+
# :ssl_client_cert [OpenSSL::X509::Certificate]
|
61
|
+
# Client certificate.
|
62
|
+
#
|
63
|
+
# :ssl_client_key [OpenSSL::PKey::RSA | OpenSSL::PKey::DSA]
|
64
|
+
# Client key.
|
65
|
+
#
|
66
|
+
# source_type: [String]
|
67
|
+
# Optional: Source type to display in Splunk
|
68
|
+
#
|
69
|
+
# application: [String]
|
70
|
+
# The :source forwarded to Splunk
|
71
|
+
# Default: SemanticLogger.application
|
72
|
+
#
|
73
|
+
# host: [String]
|
74
|
+
# Name of this host to appear in log messages.
|
75
|
+
# Default: SemanticLogger.host
|
76
|
+
#
|
77
|
+
# level: [:trace | :debug | :info | :warn | :error | :fatal]
|
78
|
+
# Override the log level for this appender.
|
79
|
+
# Default: SemanticLogger.default_level
|
80
|
+
#
|
81
|
+
# formatter: [Object|Proc]
|
82
|
+
# An instance of a class that implements #call, or a Proc to be used to format
|
83
|
+
# the output from this appender
|
84
|
+
# Default: Use the built-in formatter (See: #call)
|
85
|
+
#
|
86
|
+
# filter: [Regexp|Proc]
|
87
|
+
# RegExp: Only include log messages where the class name matches the supplied.
|
88
|
+
# regular expression. All other messages will be ignored.
|
89
|
+
# Proc: Only include log messages where the supplied Proc returns true
|
90
|
+
# The Proc must return true or false.
|
91
|
+
def initialize(index: 'main', source_type: nil,
|
92
|
+
level: nil, formatter: nil, filter: nil, application: nil, host: nil, &block)
|
93
|
+
@index = index
|
94
|
+
@source_type = source_type
|
92
95
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
+
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
97
|
+
reopen
|
98
|
+
end
|
96
99
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
# After forking an active process call #reopen to re-open
|
101
|
+
# open the handles to resources
|
102
|
+
def reopen
|
103
|
+
# Connect to splunk. Connect is a synonym for creating a Service by hand and calling login.
|
104
|
+
self.service = Splunk.connect(config)
|
102
105
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
+
# The index we are logging to
|
107
|
+
self.service_index = service.indexes[index]
|
108
|
+
end
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
# Log the message to Splunk
|
111
|
+
def log(log)
|
112
|
+
event = formatter.call(log, self)
|
113
|
+
service_index.submit(event.delete(:message), event)
|
114
|
+
true
|
115
|
+
end
|
113
116
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
117
|
+
# Returns [Hash] To send to Splunk.
|
118
|
+
#
|
119
|
+
# For splunk format requirements see:
|
120
|
+
# http://dev.splunk.com/view/event-collector/SP-CAAAE6P
|
121
|
+
def call(log, logger)
|
122
|
+
h = SemanticLogger::Formatters::Raw.new.call(log, logger)
|
123
|
+
h.delete(:time)
|
124
|
+
message = {
|
125
|
+
source: logger.application,
|
126
|
+
host: logger.host,
|
127
|
+
time: log.time.utc.to_f,
|
128
|
+
message: h.delete(:message),
|
129
|
+
event: h
|
130
|
+
}
|
131
|
+
message[:source_type] = source_type if source_type
|
132
|
+
message
|
133
|
+
end
|
134
|
+
end
|
130
135
|
end
|
131
136
|
end
|