semantic_logger 2.9.0 → 2.9.1

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: 05fe9c7ccd2177383e5f4a8cf4b5b6d0bf84df71
4
- data.tar.gz: 0516f2bb270d5ea5d78b67217fd02745ebe4c3ce
3
+ metadata.gz: 16021fcc1001bf8f9a7805c0e041856ac2a8e7d4
4
+ data.tar.gz: c5cc838698726569a32679031348e8d6e970d0df
5
5
  SHA512:
6
- metadata.gz: 39f2f6909cdd7e1623fd099226849a2086873b52334ddabbde84067a12b3e88d1058384b346f09c11f1c3c357b38758ae6e51dd649e3d39f2765304f40ac59d5
7
- data.tar.gz: 025cca0bde8b1733a023ba9139b474d9f14e85444b518e24764b2a346aa8676be5441e4e006866caf8a103027156e4c39f8b30af3cfd144d93a2fc96f26840ed
6
+ metadata.gz: 55d8f67c85aa0d40e31d566b63a2baffd5aadaff647c147f9856154c64d2fb8e34f2a690de923c1238175b41ae85a8f6c366fb33c69b2dd8e4690c3909f20b0e
7
+ data.tar.gz: bcf75d343fec7bf5c0f13b1260ed735ef0cedbea19bf6530010c91e8ca3744dc3698d90f5214e0b7359e6a7f7248accfded5a9a3d38cfae572c504d5c4102a0e
@@ -72,10 +72,14 @@ module SemanticLogger
72
72
  # trace entries are mapped to debug since :trace is not supported by the
73
73
  # Ruby or Rails Loggers
74
74
  def log(log)
75
+ # Ensure minimum log level is met, and check filter
76
+ return false if (level_index > (log.level_index || 0)) || !include_message?(log)
77
+
75
78
  # Since only one appender thread will be writing to the file at a time
76
79
  # it is not necessary to protect access to the file with a semaphore
77
80
  # Allow this logger to filter out log levels lower than it's own
78
- @log.write(@formatter.call(log) << "\n") if level_index <= (log.level_index || 0)
81
+ @log.write(@formatter.call(log) << "\n")
82
+ true
79
83
  end
80
84
 
81
85
  # Flush all pending logs to disk.
@@ -178,8 +178,12 @@ module SemanticLogger
178
178
 
179
179
  # Log the message to MongoDB
180
180
  def log(log)
181
+ # Ensure minimum log level is met, and check filter
182
+ return false if (level_index > (log.level_index || 0)) || !include_message?(log)
183
+
181
184
  # Insert log entry into Mongo
182
- collection.insert(formatter.call(log), :w=>@write_concern) if level_index <= (log.level_index || 0)
185
+ collection.insert(formatter.call(log), :w=>@write_concern)
186
+ true
183
187
  end
184
188
 
185
189
  end
@@ -92,14 +92,14 @@ class SemanticLogger::Appender::NewRelic < SemanticLogger::Appender::Base
92
92
 
93
93
  # Send an error notification to New Relic
94
94
  def log(log)
95
- # Ensure minimum log level is met.
96
- return false unless level_index <= (log.level_index || 0)
95
+ # Ensure minimum log level is met, and check filter
96
+ return false if (level_index > (log.level_index || 0)) || !include_message?(log)
97
97
 
98
98
  # For more documentation on the NewRelic::Agent.notice_error method see:
99
99
  # http://rubydoc.info/github/newrelic/rpm/NewRelic/Agent#notice_error-instance_method
100
100
  # and https://docs.newrelic.com/docs/ruby/ruby-agent-api
101
101
  NewRelic::Agent.notice_error(log.exception || self.class.first_non_empty_line(log.message), formatter.call(log))
102
- return true
102
+ true
103
103
  end
104
104
 
105
105
  end
@@ -48,12 +48,12 @@ module SemanticLogger
48
48
  # ::Syslog::LOG_INFO - "Informational message"
49
49
  # ::Syslog::LOG_DEBUG - "Debugging information"
50
50
  DEFAULT_LEVEL_MAP = {
51
- :fatal => ::Syslog::LOG_CRIT,
52
- :error => ::Syslog::LOG_ERR,
53
- :warn => ::Syslog::LOG_WARNING,
54
- :info => ::Syslog::LOG_NOTICE,
55
- :debug => ::Syslog::LOG_INFO,
56
- :trace => ::Syslog::LOG_DEBUG
51
+ :fatal => ::Syslog::LOG_CRIT,
52
+ :error => ::Syslog::LOG_ERR,
53
+ :warn => ::Syslog::LOG_WARNING,
54
+ :info => ::Syslog::LOG_NOTICE,
55
+ :debug => ::Syslog::LOG_INFO,
56
+ :trace => ::Syslog::LOG_DEBUG
57
57
  }
58
58
 
59
59
  # For more information on the Syslog constants used below see http://ruby-doc.org/stdlib-2.0.0/libdoc/syslog/rdoc/Syslog.html
@@ -176,24 +176,24 @@ module SemanticLogger
176
176
  end
177
177
 
178
178
  case @protocol
179
- when :syslog
180
- ::Syslog.open(@ident, options, @facility)
181
- 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
- # Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
192
- @remote_syslog.logger = SemanticLogger::Logger.logger
193
- when :udp
194
- @remote_syslog = UDPSocket.new
195
- else
196
- raise "Unsupported protocol: #{protocol}"
179
+ when :syslog
180
+ ::Syslog.open(@ident, options, @facility)
181
+ 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
+ # Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
192
+ @remote_syslog.logger = SemanticLogger::Logger.logger
193
+ when :udp
194
+ @remote_syslog = UDPSocket.new
195
+ else
196
+ raise "Unsupported protocol: #{protocol}"
197
197
  end
198
198
 
199
199
  super(level, filter, &block)
@@ -201,18 +201,20 @@ module SemanticLogger
201
201
 
202
202
  # Write the log using the specified protocol and host.
203
203
  def log(log)
204
- if level_index <= (log.level_index || 0)
205
- case @protocol
206
- when :syslog
207
- ::Syslog.log @level_map[log.level], formatter.call(log)
208
- when :tcp
209
- @remote_syslog.retry_on_connection_failure { @remote_syslog.write("#{syslog_packet_formatter(log)}\r\n") }
210
- when :udp
211
- @remote_syslog.send syslog_packet_formatter(log), 0, @host, @port
212
- else
213
- raise "Unsupported protocol: #{protocol}"
214
- end
204
+ # Ensure minimum log level is met, and check filter
205
+ return false if (level_index > (log.level_index || 0)) || !include_message?(log)
206
+
207
+ case @protocol
208
+ when :syslog
209
+ ::Syslog.log @level_map[log.level], formatter.call(log)
210
+ when :tcp
211
+ @remote_syslog.retry_on_connection_failure { @remote_syslog.write("#{syslog_packet_formatter(log)}\r\n") }
212
+ when :udp
213
+ @remote_syslog.send syslog_packet_formatter(log), 0, @host, @port
214
+ else
215
+ raise "Unsupported protocol: #{protocol}"
215
216
  end
217
+ true
216
218
  end
217
219
 
218
220
  # Flush is called by the semantic_logger during shutdown.
@@ -40,7 +40,12 @@ module SemanticLogger
40
40
  # trace entries are mapped to debug since :trace is not supported by the
41
41
  # Ruby or Rails Loggers
42
42
  def log(log)
43
+ # Check filter
44
+ return false unless include_message?(log)
45
+
46
+ # Underlying wrapper logger implements log level, so don't check here
43
47
  @logger.send(log.level == :trace ? :debug : log.level, @formatter.call(log))
48
+ true
44
49
  end
45
50
 
46
51
  # Flush all pending logs to disk.
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger #:nodoc
2
- VERSION = "2.9.0"
2
+ VERSION = "2.9.1"
3
3
  end
data/test/logger_test.rb CHANGED
@@ -12,13 +12,14 @@ class LoggerTest < Test::Unit::TestCase
12
12
  context SemanticLogger::Logger do
13
13
  # Test each filter
14
14
  [ nil, /\ALogger/, Proc.new{|l| (/\AExclude/ =~ l.message).nil? } ].each do |filter|
15
- context "filter: #{filter.inspect}" do
15
+ context "filter: #{filter.class.name}" do
16
16
  setup do
17
17
  # Use a mock logger that just keeps the last logged entry in an instance
18
18
  # variable
19
19
  SemanticLogger.default_level = :trace
20
20
  @mock_logger = MockLogger.new
21
- SemanticLogger.add_appender(@mock_logger)
21
+ appender = SemanticLogger.add_appender(@mock_logger)
22
+ appender.filter = filter
22
23
 
23
24
  # Add mock metric subscriber
24
25
  $last_metric = nil
@@ -27,7 +28,7 @@ class LoggerTest < Test::Unit::TestCase
27
28
  end
28
29
 
29
30
  # Use this test's class name as the application name in the log output
30
- @logger = SemanticLogger::Logger.new(self.class, :trace, filter)
31
+ @logger = SemanticLogger[self.class]
31
32
  @hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
32
33
  @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
33
34
  assert_equal [], @logger.tags
@@ -54,6 +55,16 @@ class LoggerTest < Test::Unit::TestCase
54
55
  assert_nil @mock_logger.message
55
56
  end
56
57
  end
58
+
59
+ should "exclude log messages using RegExp filter" do
60
+ if filter.is_a?(Regexp)
61
+ logger = SemanticLogger::Logger.new('NotLogger', :trace, filter)
62
+ logger.send(level, 'Ignore all log messages from this class', @hash) { "Calculations" }
63
+ SemanticLogger.flush
64
+ assert_nil @mock_logger.message
65
+ end
66
+ end
67
+
57
68
  end
58
69
  end
59
70
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.9.1
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-06-25 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sync_attr