semantic_logger 2.18.0 → 2.19.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: 60df9242109f0c836e1375c4c21d5b0a85165e34
4
- data.tar.gz: 47e1799788d85898b1ff7501ba99e460c78a815f
3
+ metadata.gz: 8edd7638dee098976eeee0f818ea64c213da2a1f
4
+ data.tar.gz: a03fac478e80e0784e765a7c2f28c8c6b929b94b
5
5
  SHA512:
6
- metadata.gz: 304af80d0e158f72a2dd5a90f8ac1e56dd8955bcfd26b4cec84862c0347ba5fb5b93ae4d6e76cdf6f48f3f84bb6310c9dfa703f36534bc253c64020d91576cd2
7
- data.tar.gz: 0b1064e891a59877f1e991a19e73e2a1f10aac25e4621df25c311bd7d903df68144df37a88d5bc13b6e456a86446d14e43ad5834fa5009e2eb651745de5d0e6c
6
+ metadata.gz: 9f85f11748ef85c23dbd912fa5a690d57cd50af051edaeb37014ba30ef987e9f22866b0632f457327c78f6243e88b242c2fe3cc4c46135b8b2f64c298de9961e
7
+ data.tar.gz: 1b5ac351139f57b94743022465f86030a8959df41e696fdcb048b4f3f07adfa1736bc21d9f4de74c6b8e0434a5d32ee44c79b7c26df4272a0201a78da8bb017a
data/README.md CHANGED
@@ -11,7 +11,7 @@ Low latency, high throughput, enterprise-scale logging system for Ruby
11
11
 
12
12
  [Reference Documentation](http://www.rubydoc.info/gems/semantic_logger/)
13
13
 
14
- ## Supports
14
+ ## Logging Destinations
15
15
 
16
16
  Logging to the following destinations are all supported "out-of-the-box":
17
17
 
@@ -59,8 +59,8 @@ module SemanticLogger
59
59
  entry << " -- #{log.message}" if log.message
60
60
 
61
61
  # Payload
62
- unless log.payload.nil? || (log.payload.respond_to?(:empty?) && log.payload.empty?)
63
- entry << ' -- ' << log.payload.inspect
62
+ if payload = log.payload_to_s(false)
63
+ entry << ' -- ' << payload
64
64
  end
65
65
 
66
66
  # Exceptions
@@ -83,7 +83,7 @@ module SemanticLogger
83
83
  level_color = colors::LEVEL_MAP[log.level]
84
84
 
85
85
  # Header with date, time, log level and process info
86
- entry = "#{log.formatted_time} #{level_color}#{log.level_to_s}#{colors::CLEAR} [#{log.process_info}]"
86
+ entry = "#{log.formatted_time} #{level_color}#{log.level_to_s}#{colors::CLEAR} [#{log.process_info}]"
87
87
 
88
88
  # Tags
89
89
  entry << ' ' << log.tags.collect { |tag| "[#{level_color}#{tag}#{colors::CLEAR}]" }.join(' ') if log.tags && (log.tags.size > 0)
@@ -98,9 +98,7 @@ module SemanticLogger
98
98
  entry << " -- #{log.message}" if log.message
99
99
 
100
100
  # Payload
101
- unless log.payload.nil? || (log.payload.respond_to?(:empty?) && log.payload.empty?)
102
- payload = log.payload
103
- payload = (defined?(AwesomePrint) && payload.respond_to?(:ai)) ? payload.ai(multiline: false) : payload.inspect
101
+ if payload = log.payload_to_s(true)
104
102
  entry << ' -- ' << payload
105
103
  end
106
104
 
@@ -123,8 +121,7 @@ module SemanticLogger
123
121
  @level || :trace
124
122
  end
125
123
 
126
- ############################################################################
127
- protected
124
+ private
128
125
 
129
126
  # Initializer for Abstract Class SemanticLogger::Appender
130
127
  #
@@ -237,8 +237,7 @@ module SemanticLogger
237
237
  SemanticLogger.default_level
238
238
  end
239
239
 
240
- ############################################################################
241
- protected
240
+ private
242
241
 
243
242
  # Initializer for Abstract Class SemanticLogger::Base
244
243
  #
@@ -124,6 +124,16 @@ module SemanticLogger
124
124
  message.to_s.gsub(/(\e(\[([\d;]*[mz]?))?)?/, '').strip
125
125
  end
126
126
 
127
+ # Return the payload in text form
128
+ # Returns nil if payload is missing or empty
129
+ def payload_to_s(colorized = false)
130
+ return if payload.nil? || (payload.respond_to?(:empty?) && payload.empty?)
131
+ return payload.inspect if !colorized || !defined?(AwesomePrint) || !payload.respond_to?(:ai)
132
+
133
+ # Colorize the payload if the AwesomePrint gem is loaded
134
+ payload.ai(multiline: false) rescue payload.inspect
135
+ end
136
+
127
137
  if defined? JRuby
128
138
  # Return the Time as a formatted string
129
139
  # JRuby only supports time in ms
@@ -1,5 +1,3 @@
1
- require 'sync_attr'
2
-
3
1
  # Logger class variable mix-in
4
2
  #
5
3
  # Lazy initialize a logger class variable with instance accessor
@@ -31,9 +29,8 @@ module SemanticLogger
31
29
 
32
30
  def self.included(base)
33
31
  base.class_eval do
34
- # Thread safe logger class variable initializer
35
- sync_cattr_reader :logger do
36
- SemanticLogger[self]
32
+ def self.logger
33
+ @semantic_logger ||= SemanticLogger[self]
37
34
  end
38
35
  end
39
36
  end
@@ -1,22 +1,8 @@
1
- require 'thread_safe'
2
-
3
- # Logger stores the class name to be used for all log messages so that every
4
- # log message written by this instance will include the class name
1
+ require 'concurrent'
5
2
  module SemanticLogger
3
+ # Logger stores the class name to be used for all log messages so that every
4
+ # log message written by this instance will include the class name
6
5
  class Logger < Base
7
-
8
- # DO NOT USE. Adding unused formatter to support Rails 4 logging
9
- # Formatters must be set at the appender level, not at the logger level
10
- #
11
- # Due to the following code in Rails::Server#start that cannot be changed
12
- # without patching the entire method
13
- # console = ActiveSupport::Logger.new($stdout)
14
- # console.formatter = Rails.logger.formatter
15
- # console.level = Rails.logger.level
16
- #
17
- # Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
18
- attr_accessor :formatter
19
-
20
6
  # Returns a Logger instance
21
7
  #
22
8
  # Return the logger for a specific class, supports class specific log levels
@@ -120,11 +106,10 @@ module SemanticLogger
120
106
  # puts "#{log_struct.metric} was received. Log Struct: #{log_struct.inspect}"
121
107
  # end
122
108
  def self.on_metric(&block)
123
- (@@metric_subscribers ||= ThreadSafe::Array.new) << block
109
+ (@@metric_subscribers ||= Concurrent::Array.new) << block
124
110
  end
125
111
 
126
- ############################################################################
127
- protected
112
+ private
128
113
 
129
114
  @@appender_thread = nil
130
115
  @@queue = Queue.new
@@ -1,4 +1,4 @@
1
- require 'thread_safe'
1
+ require 'concurrent'
2
2
  module SemanticLogger
3
3
  # Logging levels in order of most detailed to most severe
4
4
  LEVELS = [:trace, :debug, :info, :warn, :error, :fatal]
@@ -246,14 +246,10 @@ module SemanticLogger
246
246
  true
247
247
  end
248
248
 
249
- ############################################################################
250
- protected
251
-
252
- @@appenders = ThreadSafe::Array.new
253
-
254
- ############################################################################
255
249
  private
256
250
 
251
+ @@appenders = Concurrent::Array.new
252
+
257
253
  def self.default_level_index
258
254
  Thread.current[:semantic_logger_silence] || @@default_level_index
259
255
  end
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger #:nodoc
2
- VERSION = '2.18.0'
2
+ VERSION = '2.19.0'
3
3
  end
@@ -8,42 +8,73 @@ end
8
8
  # Unit Test for SemanticLogger::Appender::File
9
9
  #
10
10
  class AppenderFileTest < Minitest::Test
11
+ class Base
12
+ include SemanticLogger::Loggable
13
+ end
14
+
15
+ class Subclass < Base
16
+ end
17
+
11
18
  describe SemanticLogger::Loggable do
12
- before do
13
- @time = Time.new
14
- @io = StringIO.new
15
- @appender = SemanticLogger::Appender::File.new(@io)
16
- SemanticLogger.default_level = :trace
17
- @mock_logger = MockLogger.new
18
- @appender = SemanticLogger.add_appender(@mock_logger)
19
- @hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12345}
20
- @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
21
- @thread_name = Thread.current.name
22
- end
19
+ describe 'inheritance' do
20
+ it 'should give child classes their own logger' do
21
+ assert_equal Subclass.name, Subclass.logger.name
22
+ assert_equal Base.name, Base.logger.name
23
+ assert_equal Subclass.name, Subclass.logger.name
24
+ child_logger = Subclass.logger
25
+ refute_equal child_logger, Base.logger
26
+ assert_equal child_logger.object_id, Subclass.logger.object_id
27
+ end
23
28
 
24
- after do
25
- SemanticLogger.remove_appender(@appender)
29
+ it 'should give child objects their own logger' do
30
+ subclass = Subclass.new
31
+ base = Base.new
32
+ assert_equal subclass.class.name, subclass.logger.name
33
+ assert_equal base.class.name, base.logger.name
34
+ assert_equal subclass.class.name, subclass.logger.name
35
+ child_logger = subclass.logger
36
+ refute_equal child_logger, base.logger
37
+ assert_equal child_logger.object_id, subclass.logger.object_id
38
+ end
26
39
  end
27
40
 
28
- describe 'for each log level' do
29
- # Ensure that any log level can be logged
30
- SemanticLogger::LEVELS.each do |level|
31
- it "log #{level} information with class attribute" do
32
- SemanticLogger.stub(:backtrace_level_index, 0) do
33
- SemanticLogger.stub(:appenders, [@appender]) do
34
- TestAttribute.logger.send(level, "hello #{level}", @hash)
35
- SemanticLogger.flush
36
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:#{@thread_name} loggable_test.rb:\d+\] TestAttribute -- hello #{level} -- #{@hash_str}/, @mock_logger.message
41
+ describe 'logger' do
42
+ before do
43
+ @time = Time.new
44
+ @io = StringIO.new
45
+ @appender = SemanticLogger::Appender::File.new(@io)
46
+ SemanticLogger.default_level = :trace
47
+ @mock_logger = MockLogger.new
48
+ @appender = SemanticLogger.add_appender(@mock_logger)
49
+ @hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12345}
50
+ @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
51
+ @thread_name = Thread.current.name
52
+ end
53
+
54
+ after do
55
+ SemanticLogger.remove_appender(@appender)
56
+ end
57
+
58
+ describe 'for each log level' do
59
+ # Ensure that any log level can be logged
60
+ SemanticLogger::LEVELS.each do |level|
61
+ it "log #{level} information with class attribute" do
62
+ SemanticLogger.stub(:backtrace_level_index, 0) do
63
+ SemanticLogger.stub(:appenders, [@appender]) do
64
+ TestAttribute.logger.send(level, "hello #{level}", @hash)
65
+ SemanticLogger.flush
66
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:#{@thread_name} loggable_test.rb:\d+\] TestAttribute -- hello #{level} -- #{@hash_str}/, @mock_logger.message
67
+ end
37
68
  end
38
69
  end
39
- end
40
70
 
41
- it "log #{level} information with instance attribute" do
42
- SemanticLogger.stub(:backtrace_level_index, 0) do
43
- SemanticLogger.stub(:appenders, [@appender]) do
44
- TestAttribute.new.logger.send(level, "hello #{level}", @hash)
45
- SemanticLogger.flush
46
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:#{@thread_name} loggable_test.rb:\d+\] TestAttribute -- hello #{level} -- #{@hash_str}/, @mock_logger.message
71
+ it "log #{level} information with instance attribute" do
72
+ SemanticLogger.stub(:backtrace_level_index, 0) do
73
+ SemanticLogger.stub(:appenders, [@appender]) do
74
+ TestAttribute.new.logger.send(level, "hello #{level}", @hash)
75
+ SemanticLogger.flush
76
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:#{@thread_name} loggable_test.rb:\d+\] TestAttribute -- hello #{level} -- #{@hash_str}/, @mock_logger.message
77
+ end
47
78
  end
48
79
  end
49
80
  end
@@ -97,7 +97,7 @@ class LoggerTest < Minitest::Test
97
97
  end
98
98
  end
99
99
 
100
- it 'add payload to log entries' do
100
+ it 'logs tagged payload' do
101
101
  hash = {tracking_number: "123456", even: 2, more: "data"}
102
102
  hash_str = hash.inspect.sub("{", "\\{").sub("}", "\\}")
103
103
  @logger.with_payload(tracking_number: '123456') do
@@ -108,6 +108,21 @@ class LoggerTest < Minitest::Test
108
108
  end
109
109
  end
110
110
  end
111
+
112
+ it 'logs payload' do
113
+ hash = {tracking_number: "123456", even: 2, more: "data"}
114
+ hash_str = hash.inspect.sub("{", "\\{").sub("}", "\\}")
115
+ @logger.info('Hello world', hash)
116
+ SemanticLogger.flush
117
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
118
+ end
119
+
120
+ it 'does not log an empty payload' do
121
+ hash = {}
122
+ @logger.info('Hello world', hash)
123
+ SemanticLogger.flush
124
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message
125
+ end
111
126
  end
112
127
 
113
128
  describe 'Ruby Logger' do
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.18.0
4
+ version: 2.19.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: 2015-11-11 00:00:00.000000000 Z
11
+ date: 2015-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sync_attr
14
+ name: concurrent-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
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
- version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: thread_safe
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.1'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.1'
26
+ version: '1.0'
41
27
  description: Next generation logging system for Ruby to support highly concurrent,
42
28
  high throughput, low latency enterprise systems
43
29
  email: