semantic_logger 4.2.0 → 4.2.1

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