semantic_logger 2.10.0 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0114b0cd9c89056b16e797dad89c995cc0fb9485
4
- data.tar.gz: f2df244261d122b2967e973380cf94770b24325e
3
+ metadata.gz: d8ef6f216370a6763f9cd28aa1c5a098c1cc584e
4
+ data.tar.gz: c02264af59deef219f5970e8ec51b4af852ed48e
5
5
  SHA512:
6
- metadata.gz: 2eb3829a86b55f7b0014e72a0c624970f134ebc1e9c25ad7a89298078a4d71a993728ec0817f5205fa3afcd82d96186f5dc2e649cceab1e0502bdbfde3cd7845
7
- data.tar.gz: 614edca05b62f3de8b48c301c2e059868e607ebea3e4eaa25aacb6fe86e7cde3e83f24fe86b7ca21ac007ff8a96dc217aaaf8c14062e0574003b98876fffcc1c
6
+ metadata.gz: e5bf5e189ddccbcf52c57be758a53d8224777ec4a35c2beea4502a3c271cb15e82078ca67ab1aec4da5f5d80a1cf01ef4e8ccea20d9623c442eba0bc272a39b0
7
+ data.tar.gz: 4299412a428431a41126a3e6ba47ea6a3c19867c2393162dd61e02d8c6cda8ca5b084405cb1203bb7fc25044d5a47b6cf9e790ddf34fdccbd7b538d57903c1d0
data/README.md CHANGED
@@ -7,19 +7,21 @@ Next generation logging system for Ruby to support highly concurrent, high throu
7
7
 
8
8
  ## Documentation
9
9
 
10
- For complete documentation see: http://reidmorrison.github.io/semantic_logger
10
+ [Semantic Logger Guide](http://reidmorrison.github.io/semantic_logger)
11
+
12
+ API Documentation: [![semantic_logger API Documentation](https://www.omniref.com/ruby/gems/semantic_logger.png)](https://www.omniref.com/ruby/gems/semantic_logger)
11
13
 
12
14
  ## Dependencies
13
15
 
14
16
  Semantic Logger supports the following Ruby platforms:
15
- - Ruby 1.9.3, 2.0, 2.1
17
+ - Ruby 1.9.3, 2.x
16
18
  - JRuby 1.7
17
19
 
18
20
  The following gems are only required when their corresponding appenders are being used,
19
21
  and are therefore not automatically included by this gem:
20
22
  - MongoDB Appender: gem 'mongo' 1.9.2 or above
21
23
  - Syslog Appender: gem 'syslog_protocol' 0.9.2 or above
22
- - Syslog Appender to a remote syslogng server over TCP or UDP: gem 'resilient_socket' 0.5.0 or above
24
+ - Syslog Appender to a remote syslogng server over TCP or UDP: gem 'net_tcp_client'
23
25
  - Splunk Appender: gem 'splunk-sdk-ruby'
24
26
 
25
27
  ## Install
@@ -58,7 +60,7 @@ This project uses [Semantic Versioning](http://semver.org/).
58
60
 
59
61
  ## License
60
62
 
61
- Copyright 2012, 2013, 2014 Reid Morrison
63
+ Copyright 2012, 2013, 2014, 2015 Reid Morrison
62
64
 
63
65
  Licensed under the Apache License, Version 2.0 (the "License");
64
66
  you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ module SemanticLogger
30
30
  # }
31
31
  #
32
32
  class MongoDB < SemanticLogger::Appender::Base
33
- attr_reader :db, :collection_name
33
+ attr_reader :db, :collection_name, :collection
34
34
  attr_accessor :host_name, :write_concern, :application
35
35
 
36
36
  # Create a MongoDB Appender instance
@@ -52,7 +52,7 @@ module SemanticLogger
52
52
  # :write_concern [Integer]
53
53
  # Write concern to use
54
54
  # see: http://docs.mongodb.org/manual/reference/write-concern/
55
- # Default: 0
55
+ # Default: 1
56
56
  #
57
57
  # :application [String]
58
58
  # Name of the application to include in the document written to mongo
@@ -83,7 +83,7 @@ module SemanticLogger
83
83
  @db = params[:db] || raise('Missing mandatory parameter :db')
84
84
  @collection_name = params[:collection_name] || 'semantic_logger'
85
85
  @host_name = params[:host_name] || Socket.gethostname.split('.').first
86
- @write_concern = params[:write_concern] || 0
86
+ @write_concern = params[:write_concern] || 1
87
87
  @application = params[:application]
88
88
  filter = params[:filter]
89
89
 
@@ -91,6 +91,8 @@ module SemanticLogger
91
91
  @collection_size = params[:collection_size] || 1024**3
92
92
  @collection_max = params[:collection_max]
93
93
 
94
+ reopen
95
+
94
96
  # Create the collection and necessary indexes
95
97
  create_indexes
96
98
 
@@ -98,6 +100,12 @@ module SemanticLogger
98
100
  super(params[:level], filter, &block)
99
101
  end
100
102
 
103
+ # After forking an active process call #reopen to re-open
104
+ # open the handles to resources
105
+ def reopen
106
+ @collection = db[@collection_name]
107
+ end
108
+
101
109
  # Create the required capped collection
102
110
  # Features of capped collection:
103
111
  # * No indexes by default (not even on _id)
@@ -111,7 +119,7 @@ module SemanticLogger
111
119
  options = {:capped => true, :size => @collection_size}
112
120
  options[:max] = @collection_max if @collection_max
113
121
  db.create_collection(collection_name, options)
114
- collection.ensure_index('tags')
122
+ db[@collection_name].ensure_index('tags')
115
123
  end
116
124
 
117
125
  # Purge all data from the capped collection by dropping the collection
@@ -123,11 +131,6 @@ module SemanticLogger
123
131
  create_indexes
124
132
  end
125
133
 
126
- # Return the collection being used to write the log document to
127
- def collection
128
- @collection ||= db[collection_name]
129
- end
130
-
131
134
  # Flush all pending logs to disk.
132
135
  # Waits for all sent documents to be written to disk
133
136
  def flush
@@ -182,7 +185,7 @@ module SemanticLogger
182
185
  return false if (level_index > (log.level_index || 0)) || !include_message?(log)
183
186
 
184
187
  # Insert log entry into Mongo
185
- collection.insert(formatter.call(log), :w=>@write_concern)
188
+ collection.insert(formatter.call(log), w: @write_concern)
186
189
  true
187
190
  end
188
191
 
@@ -1,8 +1,6 @@
1
1
  require 'splunk-sdk-ruby'
2
2
 
3
-
4
- # Recommended not to use the colorized formatter.
5
-
3
+ # Note: Not recommended to use the colorized formatter.
6
4
  class SemanticLogger::Appender::Splunk < SemanticLogger::Appender::Base
7
5
  attr_reader :config, :index, :service, :service_index
8
6
 
@@ -12,17 +10,22 @@ class SemanticLogger::Appender::Splunk < SemanticLogger::Appender::Base
12
10
  # Parse input options for setting up splunk connection
13
11
  parse_options(options)
14
12
 
13
+ reopen
14
+
15
+ # Pass on the level and custom formatter if supplied
16
+ super(level, &block)
17
+ end
18
+
19
+ # After forking an active process call #reopen to re-open
20
+ # open the handles to resources
21
+ def reopen
15
22
  # Connect to splunk. Connect is a synonym for creating a Service by hand and calling login.
16
23
  @service = Splunk::connect(@config)
17
24
 
18
25
  # The index we are logging to
19
26
  @service_index = @service.indexes[@index]
20
-
21
- # Pass on the level and custom formatter if supplied
22
- super(level, &block)
23
27
  end
24
28
 
25
-
26
29
  # Log the message to Splunk
27
30
  def log(log)
28
31
  # Ensure minimum log level is met, and check filter
@@ -34,23 +37,23 @@ class SemanticLogger::Appender::Splunk < SemanticLogger::Appender::Base
34
37
 
35
38
  private
36
39
 
37
- def parse_options(options)
38
- @config = {
39
- scheme: options[:scheme] || :https,
40
- host: options[:host] || 'localhost',
41
- port: options[:port] || 8089,
42
- username: options[:username],
43
- password: options[:password]
44
- }
45
-
46
- @index = options[:index]
47
-
48
- if @config[:username].nil?
49
- raise ArgumentError, 'Must supply a username.'
50
- elsif @config[:password].nil?
51
- raise ArgumentError, 'Must supply a password.'
52
- elsif @index.nil?
53
- raise ArgumentError, 'Must supply an index.'
54
- end
40
+ def parse_options(options)
41
+ @config = {
42
+ scheme: options[:scheme] || :https,
43
+ host: options[:host] || 'localhost',
44
+ port: options[:port] || 8089,
45
+ username: options[:username],
46
+ password: options[:password]
47
+ }
48
+
49
+ @index = options[:index]
50
+
51
+ if @config[:username].nil?
52
+ raise ArgumentError, 'Must supply a username.'
53
+ elsif @config[:password].nil?
54
+ raise ArgumentError, 'Must supply a password.'
55
+ elsif @index.nil?
56
+ raise ArgumentError, 'Must supply an index.'
55
57
  end
58
+ end
56
59
  end
@@ -139,29 +139,28 @@ module SemanticLogger
139
139
  # :tcp_client [Hash]
140
140
  # Default: {}
141
141
  # Only used with the TCP protocol.
142
- # Specify custom parameters to pass into ResilientSocket.TCPClient.new
143
- # For a list of options see the resilient_socket documentation:
144
- # https://github.com/reidmorrison/resilient_socket/blob/master/lib/resilient_socket/tcp_client.rb
142
+ # Specify custom parameters to pass into Net::TCPClient.new
143
+ # For a list of options see the net_tcp_client documentation:
144
+ # https://www.omniref.com/ruby/gems/net_tcp_client/1.0.0/symbols/Net::TCPClient/initialize
145
145
  def initialize(params = {}, &block)
146
- params = params.dup
147
- @ident = params.delete(:ident) || 'ruby'
148
- options = params.delete(:options) || (::Syslog::LOG_PID | ::Syslog::LOG_CONS)
149
- @facility = params.delete(:facility) || ::Syslog::LOG_USER
150
- filter = params.delete(:filter)
151
- level = params.delete(:level)
152
- level_map = params.delete(:level_map)
153
- @level_map = DEFAULT_LEVEL_MAP.dup
146
+ params = params.dup
147
+ @ident = params.delete(:ident) || 'ruby'
148
+ @options = params.delete(:options) || (::Syslog::LOG_PID | ::Syslog::LOG_CONS)
149
+ @facility = params.delete(:facility) || ::Syslog::LOG_USER
150
+ filter = params.delete(:filter)
151
+ level = params.delete(:level)
152
+ level_map = params.delete(:level_map)
153
+ @level_map = DEFAULT_LEVEL_MAP.dup
154
154
  @level_map.update(level_map) if level_map
155
- @server = params.delete(:server) || 'syslog://localhost'
156
- uri = URI(@server)
157
- @host = uri.host || 'localhost'
158
- @protocol = (uri.scheme || :syslog).to_sym
155
+ @server = params.delete(:server) || 'syslog://localhost'
156
+ uri = URI(@server)
157
+ @host = uri.host || 'localhost'
158
+ @protocol = (uri.scheme || :syslog).to_sym
159
159
  raise "Unknown protocol #{@protocol}!" unless [:syslog, :tcp, :udp].include?(@protocol)
160
- @host = 'localhost' if @protocol == :syslog
161
- @port = URI(@server).port || 514
162
-
163
- @local_hostname = params.delete(:local_hostname) || Socket.gethostname || `hostname`.strip
164
- tcp_client_options = params.delete(:tcp_client)
160
+ @host = 'localhost' if @protocol == :syslog
161
+ @port = URI(@server).port || 514
162
+ @local_hostname = params.delete(:local_hostname) || Socket.gethostname || `hostname`.strip
163
+ @tcp_client_options = params.delete(:tcp_client)
165
164
 
166
165
  # Warn about any unknown configuration options.
167
166
  params.each_pair { |key,val| SemanticLogger::Logger.logger.warn "Ignoring unknown configuration option: #{key.inspect} => #{val.inspect}" }
@@ -173,30 +172,39 @@ module SemanticLogger
173
172
  rescue LoadError
174
173
  raise 'Missing gem: syslog_protocol. This gem is required when logging over TCP or UDP. To fix this error: gem install syslog_protocol'
175
174
  end
175
+
176
+ # The net_tcp_client gem is required when logging over TCP.
177
+ if protocol == :tcp
178
+ @tcp_client_options ||= {}
179
+ @tcp_client_options[:server] = "#{@host}:#{@port}"
180
+ begin
181
+ require 'net/tcp_client'
182
+ rescue LoadError
183
+ raise 'Missing gem: net_tcp_client. This gem is required when logging over TCP. To fix this error: gem install net_tcp_client'
184
+ end
185
+ end
176
186
  end
177
187
 
188
+ reopen
189
+
190
+ super(level, filter, &block)
191
+ end
192
+
193
+ # After forking an active process call #reopen to re-open
194
+ # open the handles to resources
195
+ def reopen
178
196
  case @protocol
179
197
  when :syslog
180
- ::Syslog.open(@ident, options, @facility)
198
+ ::Syslog.open(@ident, @options, @facility)
181
199
  when :tcp
182
- # The resilient_socket gem is required when logging over TCP.
183
- begin
184
- require 'resilient_socket'
185
- rescue LoadError
186
- raise 'Missing gem: resilient_socket. This gem is required when logging over TCP. To fix this error: gem install resilient_socket'
187
- end
188
- options = tcp_client_options || {}
189
- options[:server] = "#{@host}:#{@port}"
190
- @remote_syslog = ResilientSocket::TCPClient.new(options)
191
200
  # Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
192
- @remote_syslog.logger = SemanticLogger::Logger.logger
201
+ @tcp_client_options[:logger] = SemanticLogger::Logger.logger
202
+ @remote_syslog = Net::TCPClient.new(@tcp_client_options)
193
203
  when :udp
194
204
  @remote_syslog = UDPSocket.new
195
205
  else
196
- raise "Unsupported protocol: #{protocol}"
206
+ raise "Unsupported protocol: #{@protocol}"
197
207
  end
198
-
199
- super(level, filter, &block)
200
208
  end
201
209
 
202
210
  # Write the log using the specified protocol and host.
@@ -221,7 +229,7 @@ module SemanticLogger
221
229
 
222
230
  # Flush is called by the semantic_logger during shutdown.
223
231
  def flush
224
- # TODO Add flush for :tcp.
232
+ @remote_syslog.flush if @remote_syslog && @remote_syslog.respond_to?(:flush)
225
233
  end
226
234
 
227
235
  # Custom log formatter for syslog
@@ -245,8 +253,8 @@ module SemanticLogger
245
253
  packet.hostname = @local_hostname
246
254
  packet.facility = @facility
247
255
  packet.severity = @level_map[log.level]
248
- packet.tag = @ident
249
- packet.content = default_formatter.call(log)
256
+ packet.tag = @ident
257
+ packet.content = default_formatter.call(log)
250
258
  packet.to_s
251
259
  end
252
260
  end
@@ -320,11 +320,12 @@ module SemanticLogger
320
320
  ensure
321
321
  end_time = Time.now
322
322
  # Extract options after block completes so that block can modify any of the options
323
- log_exception = params[:log_exception] || :partial
324
- min_duration = params[:min_duration] || 0.0
325
- payload = params[:payload]
326
- metric = params[:metric]
327
- duration = if block_given?
323
+ log_exception = params[:log_exception] || :partial
324
+ on_exception_level = params[:on_exception_level]
325
+ min_duration = params[:min_duration] || 0.0
326
+ payload = params[:payload]
327
+ metric = params[:metric]
328
+ duration = if block_given?
328
329
  1000.0 * (end_time - start)
329
330
  else
330
331
  params[:duration] || raise("Mandatory block missing when :duration option is not supplied")
@@ -335,14 +336,28 @@ module SemanticLogger
335
336
  payload = payload.nil? ? self.payload : self.payload.merge(payload)
336
337
  end
337
338
  if exception
339
+ logged_exception = exception
338
340
  case log_exception
339
341
  when :full
340
- struct = Log.new(level, Thread.current.name, name, message, payload, end_time, duration, tags, index, exception, metric)
341
- log(struct) if include_message?(struct)
342
+ # On exception change the log level
343
+ if on_exception_level
344
+ level = on_exception_level
345
+ index = SemanticLogger.level_to_index(level)
346
+ end
342
347
  when :partial
343
- struct = Log.new(level, Thread.current.name, name, "#{message} -- Exception: #{exception.class}: #{exception.message}", payload, end_time, duration, tags, index, nil, metric)
344
- log(struct) if include_message?(struct)
348
+ # On exception change the log level
349
+ if on_exception_level
350
+ level = on_exception_level
351
+ index = SemanticLogger.level_to_index(level)
352
+ end
353
+ message = "#{message} -- Exception: #{exception.class}: #{exception.message}"
354
+ logged_exception = nil
355
+ else
356
+ # Log the message with its duration but leave out the exception that was raised
357
+ logged_exception = nil
345
358
  end
359
+ struct = Log.new(level, Thread.current.name, name, message, payload, end_time, duration, tags, index, logged_exception, metric)
360
+ log(struct) if include_message?(struct)
346
361
  raise exception
347
362
  elsif duration >= min_duration
348
363
  # Only log if the block took longer than 'min_duration' to complete
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger #:nodoc
2
- VERSION = "2.10.0"
2
+ VERSION = "2.11.0"
3
3
  end
@@ -1,16 +1,10 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'shoulda'
7
- require 'logger'
8
- require 'semantic_logger'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
9
3
  require 'stringio'
10
4
 
11
5
  # Unit Test for SemanticLogger::Appender::File
12
6
  #
13
- class AppenderFileTest < Test::Unit::TestCase
7
+ class AppenderFileTest < Minitest::Test
14
8
  context SemanticLogger::Appender::File do
15
9
  setup do
16
10
  SemanticLogger.default_level = :trace
@@ -1,26 +1,21 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'shoulda'
7
- require 'mongo'
8
- require 'semantic_logger'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
9
3
 
10
4
  # Unit Test for SemanticLogger::Appender::MongoDB
11
5
  #
12
- class AppenderMongoDBTest < Test::Unit::TestCase
6
+ class AppenderMongoDBTest < Minitest::Test
13
7
  context SemanticLogger::Appender::MongoDB do
14
8
  setup do
15
9
  @db = Mongo::Connection.new['test']
16
10
  @appender = SemanticLogger::Appender::MongoDB.new(
17
- :db => @db,
18
- :collection_size => 10*1024**2, # 10MB
19
- :host_name => 'test',
20
- :application => 'test_application'
11
+ db: @db,
12
+ collection_size: 10*1024**2, # 10MB
13
+ host_name: 'test',
14
+ application: 'test_application',
15
+ level: :trace
21
16
  )
22
17
  @hash = { :tracking_number => 12345, :session_id => 'HSSKLEU@JDK767'}
23
- @time = Time.now
18
+ Thread.current.name = 'thread'
24
19
  end
25
20
 
26
21
  teardown do
@@ -30,12 +25,12 @@ class AppenderMongoDBTest < Test::Unit::TestCase
30
25
  context "format logs into documents" do
31
26
 
32
27
  should "handle nil name, message and hash" do
33
- @appender.log SemanticLogger::Base::Log.new(:debug)
28
+ @appender.debug
34
29
  document = @appender.collection.find_one
35
30
  assert_equal :debug, document['level']
36
31
  assert_equal nil, document['message']
37
- assert_equal nil, document['thread_name']
38
- assert_equal nil, document['time']
32
+ assert_equal 'thread', document['thread_name']
33
+ assert document['time'].is_a?(Time)
39
34
  assert_equal nil, document['payload']
40
35
  assert_equal $$, document['pid']
41
36
  assert_equal 'test', document['host_name']
@@ -43,34 +38,27 @@ class AppenderMongoDBTest < Test::Unit::TestCase
43
38
  end
44
39
 
45
40
  should "handle nil message and payload" do
46
- log = SemanticLogger::Base::Log.new(:debug)
47
- log.payload = @hash
48
- @appender.log(log)
41
+ @appender.debug(@hash)
49
42
 
50
43
  document = @appender.collection.find_one
51
44
  assert_equal :debug, document['level']
52
- assert_equal nil, document['message']
53
- assert_equal nil, document['thread_name']
54
- assert_equal nil, document['time']
55
- assert_equal({ "tracking_number" => 12345, "session_id" => 'HSSKLEU@JDK767'}, document['payload'])
45
+ assert_equal @hash.inspect, document['message']
46
+ assert_equal 'thread', document['thread_name']
47
+ assert document['time'].is_a?(Time)
48
+ assert_nil document['payload']
56
49
  assert_equal $$, document['pid']
57
50
  assert_equal 'test', document['host_name']
58
51
  assert_equal 'test_application', document['application']
59
52
  end
60
53
 
61
54
  should "handle message and payload" do
62
- log = SemanticLogger::Base::Log.new(:debug)
63
- log.message = 'hello world'
64
- log.payload = @hash
65
- log.thread_name = 'thread'
66
- log.time = @time
67
- @appender.log(log)
55
+ @appender.debug('hello world', @hash)
68
56
 
69
57
  document = @appender.collection.find_one
70
58
  assert_equal :debug, document['level']
71
59
  assert_equal 'hello world', document['message']
72
60
  assert_equal 'thread', document['thread_name']
73
- assert_equal @time.to_i, document['time'].to_i
61
+ assert document['time'].is_a?(Time)
74
62
  assert_equal({ "tracking_number" => 12345, "session_id" => 'HSSKLEU@JDK767'}, document['payload'])
75
63
  assert_equal $$, document['pid']
76
64
  assert_equal 'test', document['host_name']
@@ -79,16 +67,13 @@ class AppenderMongoDBTest < Test::Unit::TestCase
79
67
 
80
68
  should "handle message without payload" do
81
69
  log = SemanticLogger::Base::Log.new(:debug)
82
- log.message = 'hello world'
83
- log.thread_name = 'thread'
84
- log.time = @time
85
- @appender.log(log)
70
+ @appender.debug('hello world')
86
71
 
87
72
  document = @appender.collection.find_one
88
73
  assert_equal :debug, document['level']
89
74
  assert_equal 'hello world', document['message']
90
75
  assert_equal 'thread', document['thread_name']
91
- assert_equal @time.to_i, document['time'].to_i
76
+ assert document['time'].is_a?(Time)
92
77
  assert_equal nil, document['payload']
93
78
  assert_equal $$, document['pid']
94
79
  assert_equal 'test', document['host_name']
@@ -100,12 +85,12 @@ class AppenderMongoDBTest < Test::Unit::TestCase
100
85
  # Ensure that any log level can be logged
101
86
  SemanticLogger::LEVELS.each do |level|
102
87
  should "log #{level} information" do
103
- @appender.log SemanticLogger::Base::Log.new(level, 'thread', 'my_class', 'hello world -- Calculations', @hash, @time)
88
+ @appender.send(level, 'hello world -- Calculations', @hash)
104
89
  document = @appender.collection.find_one
105
90
  assert_equal level, document['level']
106
91
  assert_equal 'hello world -- Calculations', document['message']
107
92
  assert_equal 'thread', document['thread_name']
108
- assert_equal @time.to_i, document['time'].to_i
93
+ assert document['time'].is_a?(Time)
109
94
  assert_equal({ "tracking_number" => 12345, "session_id" => 'HSSKLEU@JDK767'}, document['payload'])
110
95
  assert_equal $$, document['pid']
111
96
  assert_equal 'test', document['host_name']
@@ -1,22 +1,13 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
- # Load mocked newrelic_rpm from test directory
4
1
  $LOAD_PATH.unshift File.dirname(__FILE__)
5
-
6
-
7
- require 'rubygems'
8
- require 'test/unit'
9
- require 'shoulda'
10
- require 'mocha/setup'
11
- require 'semantic_logger'
2
+ require 'test_helper'
12
3
 
13
4
  # Unit Test for SemanticLogger::Appender::NewRelic
14
5
  #
15
- class AppenderNewRelicTest < Test::Unit::TestCase
6
+ class AppenderNewRelicTest < Minitest::Test
16
7
  context SemanticLogger::Appender::NewRelic do
17
8
 
18
9
  setup do
19
- @appender = SemanticLogger::Appender::NewRelic.new
10
+ @appender = SemanticLogger::Appender::NewRelic.new(:error)
20
11
  @message = 'AppenderNewRelicTest log message'
21
12
  @multi_line_message = <<-EOSTR
22
13
 
@@ -31,48 +22,60 @@ class AppenderNewRelicTest < Test::Unit::TestCase
31
22
 
32
23
  (SemanticLogger::LEVELS - [:error, :fatal]).each do |level|
33
24
  should "not send :#{level.to_s} notifications to New Relic" do
34
- @appender.tagged('test') do
35
- @appender.send(level, "AppenderNewRelicTest #{level.to_s} message")
25
+ message = hash = nil
26
+ NewRelic::Agent.stub(:notice_error, -> msg, h { message = msg; hash = h }) do
27
+ @appender.tagged('test') do
28
+ @appender.send(level, "AppenderNewRelicTest #{level.to_s} message")
29
+ end
36
30
  end
37
- assert_nil ::NewRelic::Agent.message
38
- assert_nil ::NewRelic::Agent.hash, ::NewRelic::Agent.hash
31
+ assert_nil message
32
+ assert_nil hash
39
33
  end
40
34
  end
41
35
 
42
36
  [:error, :fatal].each do |level|
43
37
  should "send :#{level.to_s} notifications to New Relic" do
44
- @appender.tagged('test') do
45
- @appender.send(level, @message)
46
- end
47
- assert_equal @message, ::NewRelic::Agent.message
48
- assert_equal ['test'], ::NewRelic::Agent.hash[:custom_params][:tags], ::NewRelic::Agent.hash
49
- assert_equal "SemanticLogger::Appender::NewRelic/#{@message}", ::NewRelic::Agent.hash[:metric]
50
- assert_nil ::NewRelic::Agent.hash[:custom_params][:duration], ::NewRelic::Agent.hash
51
- assert_not_nil ::NewRelic::Agent.hash[:custom_params][:thread_name], ::NewRelic::Agent.hash
38
+ message = hash = nil
39
+ NewRelic::Agent.stub(:notice_error, -> msg, h { message = msg; hash = h }) do
40
+ @appender.tagged('test') do
41
+ @appender.send(level, @message)
42
+ end
43
+ end
44
+ assert_equal @message, message
45
+ assert_equal ['test'], hash[:custom_params][:tags]
46
+ assert_equal "SemanticLogger::Appender::NewRelic/#{@message}", hash[:metric]
47
+ assert_nil hash[:custom_params][:duration]
48
+ assert hash[:custom_params][:thread_name], hash.inspect
52
49
  end
53
50
  end
54
51
 
55
52
  should 'send notification to New Relic with custom attributes' do
56
- @appender.tagged('test') do
57
- @appender.with_payload({:key1 => 1, :key2 => 'a'}) do
58
- @appender.benchmark(:error, @message) do
59
- sleep 0.001
53
+ message = hash = nil
54
+ NewRelic::Agent.stub(:notice_error, -> msg, h { message = msg; hash = h }) do
55
+ @appender.tagged('test') do
56
+ @appender.with_payload({:key1 => 1, :key2 => 'a'}) do
57
+ @appender.benchmark(:error, @message) do
58
+ sleep 0.001
59
+ end
60
60
  end
61
61
  end
62
62
  end
63
- assert_equal @message, ::NewRelic::Agent.message
64
- assert_equal ['test'], ::NewRelic::Agent.hash[:custom_params][:tags], ::NewRelic::Agent.hash
65
- assert_equal "SemanticLogger::Appender::NewRelic/#{@message}", ::NewRelic::Agent.hash[:metric]
66
- assert_equal({:key1 => 1, :key2 => 'a'}, ::NewRelic::Agent.hash[:custom_params][:payload], ::NewRelic::Agent.hash)
67
- assert_not_nil ::NewRelic::Agent.hash[:custom_params][:duration], ::NewRelic::Agent.hash
68
- assert_not_nil ::NewRelic::Agent.hash[:custom_params][:thread_name], ::NewRelic::Agent.hash
63
+ assert_equal @message, message
64
+ assert_equal ['test'], hash[:custom_params][:tags], hash
65
+ assert_equal "SemanticLogger::Appender::NewRelic/#{@message}", hash[:metric]
66
+ assert_equal({:key1 => 1, :key2 => 'a'}, hash[:custom_params][:payload], hash)
67
+ assert hash[:custom_params][:duration], hash
68
+ assert hash[:custom_params][:thread_name], hash
69
69
  end
70
70
 
71
71
  should 'use the first non-blank line for a multi-line message' do
72
- @appender.tagged('test') do
73
- @appender.error @multi_line_message
72
+ message = hash = nil
73
+ NewRelic::Agent.stub(:notice_error, -> msg, h { message = msg; hash = h }) do
74
+ @appender.tagged('test') do
75
+ @appender.error @multi_line_message
76
+ end
74
77
  end
75
- assert_equal 'first non-blank line', ::NewRelic::Agent.message
78
+ assert_equal 'first non-blank line', message
76
79
  end
77
80
 
78
81
  end
@@ -1,16 +1,9 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'mocha/setup'
7
- require 'shoulda'
8
- require 'logger'
9
- require 'semantic_logger'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
10
3
 
11
4
  # Unit Test for SemanticLogger::Appender::Splunk
12
5
  #
13
- class AppenderSplunkTest < Test::Unit::TestCase
6
+ class AppenderSplunkTest < Minitest::Test
14
7
  context SemanticLogger::Appender::Splunk do
15
8
 
16
9
  context '#parse_options' do
@@ -41,14 +34,12 @@ class AppenderSplunkTest < Test::Unit::TestCase
41
34
  end
42
35
 
43
36
  context 'set default values' do
44
- # Stub the splunk connect call, and index call.
45
- setup do
46
- Splunk.expects(:connect).returns(Splunk::Service.new({}))
47
- Splunk::Service.any_instance.expects(:indexes).returns({})
48
- end
49
-
50
37
  should 'have default values' do
51
- appender = SemanticLogger::Appender::Splunk.new(username: 'username', password: 'password', index: 'index')
38
+ appender = Splunk.stub(:connect, Splunk::Service.new({})) do
39
+ Splunk::Service.stub_any_instance(:indexes, {}) do
40
+ SemanticLogger::Appender::Splunk.new(username: 'username', password: 'password', index: 'index')
41
+ end
42
+ end
52
43
  config = appender.config
53
44
  # Default host
54
45
  assert_equal 'localhost', config[:host]
@@ -1,58 +1,61 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'shoulda'
7
- require 'mocha/setup'
8
- require 'semantic_logger'
9
- require 'socket'
10
- require 'resilient_socket'
11
- require 'syslog_protocol'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
3
+ require 'net/tcp_client'
12
4
 
13
5
  # Unit Test for SemanticLogger::Appender::Syslog
14
6
  #
15
- class AppenderSyslogTest < Test::Unit::TestCase
7
+ class AppenderSyslogTest < Minitest::Test
16
8
  context SemanticLogger::Appender::Syslog do
17
9
 
18
10
  should 'handle local syslog' do
19
- ::Syslog.expects(:open).once
20
- ::Syslog.expects(:log).once
21
- syslog_appender = SemanticLogger::Appender::Syslog.new
22
- syslog_appender.debug 'AppenderSyslogTest log message'
11
+ message = nil
12
+ Syslog.stub(:open, nil) do
13
+ Syslog.stub(:log, -> level, msg { message = msg }) do
14
+ syslog_appender = SemanticLogger::Appender::Syslog.new(level: :debug)
15
+ syslog_appender.debug 'AppenderSyslogTest log message'
16
+ end
17
+ end
18
+ assert_match /D (.*?) SemanticLogger::Appender::Syslog -- AppenderSyslogTest log message/, message
23
19
  end
24
20
 
25
21
  should 'handle remote syslog over TCP' do
26
- ::ResilientSocket::TCPClient.any_instance.stubs('closed?').returns(false)
27
- ::ResilientSocket::TCPClient.any_instance.stubs('connect')
28
- ::ResilientSocket::TCPClient.any_instance.expects(:write).with{ |message| message =~ /<70>(.*?)SemanticLogger::Appender::Syslog -- AppenderSyslogTest log message\r\n/ }
29
- syslog_appender = SemanticLogger::Appender::Syslog.new(:server => 'tcp://localhost:88888')
30
- syslog_appender.debug 'AppenderSyslogTest log message'
22
+ message = nil
23
+ Net::TCPClient.stub_any_instance(:closed?, false) do
24
+ Net::TCPClient.stub_any_instance(:connect, nil) do
25
+ syslog_appender = SemanticLogger::Appender::Syslog.new(server: 'tcp://localhost:88888', level: :debug)
26
+ syslog_appender.remote_syslog.stub(:write, Proc.new { |data| message = data }) do
27
+ syslog_appender.debug 'AppenderSyslogTest log message'
28
+ end
29
+ end
30
+ end
31
+ assert_match /<70>(.*?)SemanticLogger::Appender::Syslog -- AppenderSyslogTest log message\r\n/, message
31
32
  end
32
33
 
33
34
  should 'handle remote syslog over UDP' do
34
- ::UDPSocket.any_instance.expects(:send).with{ |*params| params[0] =~ /<70>(.*?)SemanticLogger::Appender::Syslog -- AppenderSyslogTest log message/ }
35
- syslog_appender = SemanticLogger::Appender::Syslog.new(:server => 'udp://localhost:88888')
36
- syslog_appender.debug 'AppenderSyslogTest log message'
35
+ message = nil
36
+ syslog_appender = SemanticLogger::Appender::Syslog.new(server: 'udp://localhost:88888', level: :debug)
37
+ UDPSocket.stub_any_instance(:send, -> msg, num, host, port { message = msg }) do
38
+ syslog_appender.debug 'AppenderSyslogTest log message'
39
+ end
40
+ assert_match /<70>(.*?)SemanticLogger::Appender::Syslog -- AppenderSyslogTest log message/, message
37
41
  end
38
42
 
39
43
  # Should be able to log each level.
40
44
  SemanticLogger::LEVELS.each do |level|
41
45
  should "log #{level} information" do
42
- ::Syslog.expects(:open).once
43
- ::Syslog.expects(:log).once
44
- syslog_appender = SemanticLogger::Appender::Syslog.new
45
- syslog_appender.send(level, 'AppenderSyslogTest #{level.to_s} message')
46
+ Syslog.stub(:open, nil) do
47
+ Syslog.stub(:log, nil) do
48
+ syslog_appender = SemanticLogger::Appender::Syslog.new
49
+ syslog_appender.send(level, 'AppenderSyslogTest #{level.to_s} message')
50
+ end
51
+ end
46
52
  end
47
53
  end
48
54
 
49
55
  should "allow logging with %" do
50
56
  message = "AppenderSyslogTest %test"
51
57
  syslog_appender = SemanticLogger::Appender::Syslog.new
52
-
53
- assert_nothing_raised ArgumentError do
54
- syslog_appender.debug(message)
55
- end
58
+ syslog_appender.debug(message)
56
59
  end
57
60
 
58
61
  end
@@ -1,17 +1,9 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
1
  $LOAD_PATH.unshift File.dirname(__FILE__)
4
-
5
- require 'rubygems'
6
- require 'test/unit'
7
- require 'shoulda'
8
- require 'logger'
9
- require 'semantic_logger'
10
- require 'mock_logger'
2
+ require 'test_helper'
11
3
 
12
4
  # Unit Test for SemanticLogger::Appender::Wrapper
13
5
  #
14
- class AppenderWrapperTest < Test::Unit::TestCase
6
+ class AppenderWrapperTest < Minitest::Test
15
7
  context SemanticLogger::Appender::Wrapper do
16
8
  setup do
17
9
  @time = Time.new
@@ -1,21 +1,14 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'shoulda'
7
- require 'logger'
8
- require 'semantic_logger'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
9
3
  require 'stringio'
10
4
 
11
5
  class TestAttribute
12
6
  include SemanticLogger::Loggable
13
7
  end
14
8
 
15
-
16
9
  # Unit Test for SemanticLogger::Appender::File
17
10
  #
18
- class AppenderFileTest < Test::Unit::TestCase
11
+ class AppenderFileTest < Minitest::Test
19
12
  context SemanticLogger::Loggable do
20
13
  setup do
21
14
  @time = Time.new
data/test/logger_test.rb CHANGED
@@ -1,14 +1,8 @@
1
- # Allow test to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'shoulda'
7
- require 'logger'
8
- require 'semantic_logger'
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
9
3
 
10
4
  # Unit Test for SemanticLogger::Logger
11
- class LoggerTest < Test::Unit::TestCase
5
+ class LoggerTest < Minitest::Test
12
6
  context SemanticLogger::Logger do
13
7
  # Test each filter
14
8
  [ nil, /\ALogger/, Proc.new{|l| (/\AExclude/ =~ l.message).nil? } ].each do |filter|
@@ -41,11 +35,13 @@ class LoggerTest < Test::Unit::TestCase
41
35
 
42
36
  # Ensure that any log level can be logged
43
37
  SemanticLogger::LEVELS.each do |level|
38
+ level_char = level.to_s.upcase[0]
39
+
44
40
  context level do
45
41
  should "log" do
46
42
  @logger.send(level, 'hello world', @hash) { "Calculations" }
47
43
  SemanticLogger.flush
48
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
44
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
49
45
  end
50
46
 
51
47
  should "exclude log messages using Proc filter" do
@@ -73,7 +69,7 @@ class LoggerTest < Test::Unit::TestCase
73
69
  @logger.tagged('12345', 'DJHSFK') do
74
70
  @logger.info('Hello world')
75
71
  SemanticLogger.flush
76
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \[12345\] \[DJHSFK\] LoggerTest -- Hello world/, @mock_logger.message
72
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] \[12345\] \[DJHSFK\] LoggerTest -- Hello world/, @mock_logger.message
77
73
  end
78
74
  end
79
75
 
@@ -82,7 +78,7 @@ class LoggerTest < Test::Unit::TestCase
82
78
  @logger.tagged('Second Level') do
83
79
  @logger.info('Hello world')
84
80
  SemanticLogger.flush
85
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \[First Level\] \[tags\] \[Second Level\] LoggerTest -- Hello world/, @mock_logger.message
81
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] \[First Level\] \[tags\] \[Second Level\] LoggerTest -- Hello world/, @mock_logger.message
86
82
  end
87
83
  assert_equal 2, @logger.tags.count, @logger.tags
88
84
  assert_equal 'First Level', @logger.tags.first
@@ -97,7 +93,7 @@ class LoggerTest < Test::Unit::TestCase
97
93
  @logger.with_payload(:even => 2, :more => 'data') do
98
94
  @logger.info('Hello world')
99
95
  SemanticLogger.flush
100
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
96
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
101
97
  end
102
98
  end
103
99
  end
@@ -119,18 +115,19 @@ class LoggerTest < Test::Unit::TestCase
119
115
  context "benchmark" do
120
116
  # Ensure that any log level can be benchmarked and logged
121
117
  SemanticLogger::LEVELS.each do |level|
118
+ level_char = level.to_s.upcase[0]
122
119
 
123
120
  context 'direct method' do
124
121
  should "log #{level} info" do
125
122
  assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world') { "result" } # Measure duration of the supplied block
126
123
  SemanticLogger.flush
127
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
124
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
128
125
  end
129
126
 
130
127
  should "log #{level} info with payload" do
131
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :payload => @hash) { "result" } # Measure duration of the supplied block
128
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
132
129
  SemanticLogger.flush
133
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
130
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
134
131
  end
135
132
 
136
133
  should "not log #{level} info when block is faster than :min_duration" do
@@ -140,24 +137,32 @@ class LoggerTest < Test::Unit::TestCase
140
137
  end
141
138
 
142
139
  should "log #{level} info when block duration exceeds :min_duration" do
143
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 200, :payload => @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
140
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
144
141
  SemanticLogger.flush
145
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
142
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
146
143
  end
147
144
 
148
145
  should "log #{level} info with an exception" do
149
- assert_raise RuntimeError do
150
- @logger.send("benchmark_#{level}", 'hello world', :payload => @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
146
+ assert_raises RuntimeError do
147
+ @logger.send("benchmark_#{level}", 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
148
+ end
149
+ SemanticLogger.flush
150
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
151
+ end
152
+
153
+ should "change log #{level} info with an exception" do
154
+ assert_raises RuntimeError do
155
+ @logger.send("benchmark_#{level}", 'hello world', payload: @hash, on_exception_level: :fatal) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
151
156
  end
152
157
  SemanticLogger.flush
153
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
158
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ F \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
154
159
  end
155
160
 
156
161
  should "log #{level} info with metric" do
157
162
  metric_name = '/my/custom/metric'
158
163
  assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
159
164
  SemanticLogger.flush
160
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
165
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
161
166
  assert metric_name, $last_metric.metric
162
167
  end
163
168
  end
@@ -166,13 +171,13 @@ class LoggerTest < Test::Unit::TestCase
166
171
  should "log #{level} info" do
167
172
  assert_equal "result", @logger.benchmark(level, 'hello world') { "result" } # Measure duration of the supplied block
168
173
  SemanticLogger.flush
169
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
174
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
170
175
  end
171
176
 
172
177
  should "log #{level} info with payload" do
173
- assert_equal "result", @logger.benchmark(level, 'hello world', :payload => @hash) { "result" } # Measure duration of the supplied block
178
+ assert_equal "result", @logger.benchmark(level, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
174
179
  SemanticLogger.flush
175
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
180
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
176
181
  end
177
182
 
178
183
  should "not log #{level} info when block is faster than :min_duration" do
@@ -182,24 +187,24 @@ class LoggerTest < Test::Unit::TestCase
182
187
  end
183
188
 
184
189
  should "log #{level} info when block duration exceeds :min_duration" do
185
- assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 200, :payload => @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
190
+ assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
186
191
  SemanticLogger.flush
187
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
192
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
188
193
  end
189
194
 
190
195
  should "log #{level} info with an exception" do
191
- assert_raise RuntimeError do
192
- @logger.benchmark(level, 'hello world', :payload => @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
196
+ assert_raises RuntimeError do
197
+ @logger.benchmark(level, 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
193
198
  end
194
199
  SemanticLogger.flush
195
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
200
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
196
201
  end
197
202
 
198
203
  should "log #{level} info with metric" do
199
204
  metric_name = '/my/custom/metric'
200
205
  assert_equal "result", @logger.benchmark(level, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
201
206
  SemanticLogger.flush
202
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
207
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
203
208
  assert metric_name, $last_metric.metric
204
209
  end
205
210
  end
@@ -208,7 +213,7 @@ class LoggerTest < Test::Unit::TestCase
208
213
  should "log when the block performs a return" do
209
214
  assert_equal "Good", function_with_return(@logger)
210
215
  SemanticLogger.flush
211
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
216
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
212
217
  end
213
218
  end
214
219
  end
@@ -219,7 +224,7 @@ class LoggerTest < Test::Unit::TestCase
219
224
  # Make sure that benchmark still logs when a block uses return to return from
220
225
  # a function
221
226
  def function_with_return(logger)
222
- logger.benchmark_info('hello world', :payload => @hash) do
227
+ logger.benchmark_info('hello world', payload: @hash) do
223
228
  return "Good"
224
229
  end
225
230
  "Bad"
data/test/newrelic_rpm.rb CHANGED
@@ -2,20 +2,7 @@
2
2
 
3
3
  module NewRelic
4
4
  module Agent
5
- @@message = nil
6
- @@hash = nil
7
-
8
5
  def self.notice_error(message, hash)
9
- @@message = message
10
- @@hash = hash
11
- end
12
-
13
- def self.message
14
- @@message
15
- end
16
-
17
- def self.hash
18
- @@hash
19
6
  end
20
7
  end
21
8
  end
@@ -0,0 +1,13 @@
1
+ # Allow test to be run in-place without requiring a gem install
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ #require 'rubygems'
5
+ require 'minitest/autorun'
6
+ require 'minitest/reporters'
7
+ require 'minitest/stub_any_instance'
8
+ require 'shoulda/context'
9
+ require 'semantic_logger'
10
+ require 'logger'
11
+ require 'mock_logger'
12
+
13
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sync_attr
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thread_safe
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.0
33
+ version: '0.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.0
40
+ version: '0.1'
41
41
  description: Next generation logging system for Ruby to support highly concurrent,
42
42
  high throughput, low latency systems
43
43
  email:
@@ -73,6 +73,7 @@ files:
73
73
  - test/logger_test.rb
74
74
  - test/mock_logger.rb
75
75
  - test/newrelic_rpm.rb
76
+ - test/test_helper.rb
76
77
  homepage: https://github.com/reidmorrison/semantic_logger
77
78
  licenses:
78
79
  - Apache License V2.0
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  version: '0'
94
95
  requirements: []
95
96
  rubyforge_project:
96
- rubygems_version: 2.2.2
97
+ rubygems_version: 2.4.5
97
98
  signing_key:
98
99
  specification_version: 4
99
100
  summary: Scalable, next generation logging for Ruby
@@ -108,3 +109,4 @@ test_files:
108
109
  - test/logger_test.rb
109
110
  - test/mock_logger.rb
110
111
  - test/newrelic_rpm.rb
112
+ - test/test_helper.rb