semantic_logger 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/semantic_logger.rb +6 -0
- data/lib/semantic_logger/appender/base.rb +1 -1
- data/lib/semantic_logger/base.rb +10 -6
- data/lib/semantic_logger/loggable.rb +2 -2
- data/lib/semantic_logger/logger.rb +1 -10
- data/lib/semantic_logger/semantic_logger.rb +9 -2
- data/lib/semantic_logger/version.rb +1 -1
- data/test/logger_test.rb +4 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829b38191d8058cc50bd558cc22e5af6a10d61d5
|
4
|
+
data.tar.gz: b4c7d0fca2c607da3c0804d63b856c62034026ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbafd799f1667daf4465c482811bde21bfbeae462d6db1c0c5bdebee1b9a4118b933c435134fc9b5ff76e7a84fdf481450fd33ad47c304ec6d0150a171263b16
|
7
|
+
data.tar.gz: 9b7dff017d6e41e465000f363d43c839cfeccbc5c23636078f92dc1605c154bcdbef5f12f3d5f5e0d098fd6c818f4bc5ae09a78ba4691f6001becefb7cab106c
|
data/LICENSE.txt
CHANGED
@@ -186,7 +186,7 @@
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
187
187
|
identification within third-party archives.
|
188
188
|
|
189
|
-
Copyright 2012
|
189
|
+
Copyright 2012, 2013 Reid Morrison
|
190
190
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
192
192
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
@@ -956,7 +956,7 @@ Marc Bellingrath :: marrrc.b@gmail.com
|
|
956
956
|
License
|
957
957
|
-------
|
958
958
|
|
959
|
-
Copyright 2012,2013 Reid Morrison
|
959
|
+
Copyright 2012, 2013 Reid Morrison
|
960
960
|
|
961
961
|
Licensed under the Apache License, Version 2.0 (the "License");
|
962
962
|
you may not use this file except in compliance with the License.
|
data/lib/semantic_logger.rb
CHANGED
@@ -34,7 +34,7 @@ module SemanticLogger
|
|
34
34
|
Proc.new do |log|
|
35
35
|
tags = log.tags.collect { |tag| "[#{tag}]" }.join(" ") + " " if log.tags && (log.tags.size > 0)
|
36
36
|
|
37
|
-
message = log.message.to_s
|
37
|
+
message = log.message.to_s.dup
|
38
38
|
message << " -- " << log.payload.inspect if log.payload
|
39
39
|
message << " -- " << "#{log.exception.class}: #{log.exception.message}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception
|
40
40
|
|
data/lib/semantic_logger/base.rb
CHANGED
@@ -156,22 +156,26 @@ module SemanticLogger
|
|
156
156
|
# Previous method for supplying tags
|
157
157
|
alias_method :with_tags, :tagged
|
158
158
|
|
159
|
-
# Returns [Array] of [String] tags currently active for this thread
|
159
|
+
# Returns a copy of the [Array] of [String] tags currently active for this thread
|
160
160
|
# Returns nil if no tags are set
|
161
161
|
def tags
|
162
|
-
|
162
|
+
# Since tags are stored on a per thread basis this list is thread-safe
|
163
|
+
t = Thread.current[:semantic_logger_tags]
|
164
|
+
t.nil? ? [] : t.clone
|
163
165
|
end
|
164
166
|
|
165
167
|
# Add tags to the current scope
|
166
|
-
# To support: ActiveSupport::TaggedLogging V4 and above
|
167
168
|
def push_tags *tags
|
168
|
-
|
169
|
+
# Need to flatten and reject empties to support calls from Rails 4
|
170
|
+
new_tags = tags.flatten.collect(&:to_s).reject(&:empty?)
|
171
|
+
t = Thread.current[:semantic_logger_tags]
|
172
|
+
Thread.current[:semantic_logger_tags] = t.nil? ? new_tags : t.concat(new_tags)
|
169
173
|
end
|
170
174
|
|
171
175
|
# Remove specified number of tags from the current tag list
|
172
|
-
# To support: ActiveSupport::TaggedLogging V4 and above
|
173
176
|
def pop_tags(quantity=1)
|
174
|
-
|
177
|
+
t = Thread.current[:semantic_logger_tags]
|
178
|
+
t.pop(quantity) unless t.nil?
|
175
179
|
end
|
176
180
|
|
177
181
|
# Thread specific context information to be logged with every log entry
|
@@ -2,10 +2,10 @@ require 'sync_attr'
|
|
2
2
|
|
3
3
|
# Logger class variable mix-in
|
4
4
|
#
|
5
|
-
# Lazy initialize
|
5
|
+
# Lazy initialize a logger class variable with instance accessor
|
6
6
|
#
|
7
7
|
# By including this mix-in into any class it will define a class level logger
|
8
|
-
# and make it accessible via instance methods
|
8
|
+
# and also make it accessible via instance methods
|
9
9
|
#
|
10
10
|
# Example
|
11
11
|
#
|
@@ -128,7 +128,7 @@ module SemanticLogger
|
|
128
128
|
def self.logger
|
129
129
|
@@logger ||= begin
|
130
130
|
l = SemanticLogger::Appender::File.new(STDERR, :warn)
|
131
|
-
l.name =
|
131
|
+
l.name = name
|
132
132
|
l
|
133
133
|
end
|
134
134
|
end
|
@@ -212,14 +212,5 @@ module SemanticLogger
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
-
# Flush all appenders at exit, waiting for outstanding messages on the queue
|
216
|
-
# to be written first
|
217
|
-
at_exit do
|
218
|
-
flush
|
219
|
-
end
|
220
|
-
|
221
|
-
# Start appender thread on load to workaround intermittent startup issues
|
222
|
-
# with JRuby 1.8.6 under Trinidad in 1.9 mode
|
223
|
-
start_appender_thread
|
224
215
|
end
|
225
216
|
end
|
@@ -99,6 +99,11 @@ module SemanticLogger
|
|
99
99
|
SemanticLogger::Appender::Wrapper.new(appender, &block)
|
100
100
|
end
|
101
101
|
@@appenders << appender_instance
|
102
|
+
|
103
|
+
# Start appender thread if it is not already running
|
104
|
+
SemanticLogger::Logger.start_appender_thread
|
105
|
+
|
106
|
+
appender_instance
|
102
107
|
end
|
103
108
|
|
104
109
|
# Remove an existing appender
|
@@ -113,7 +118,7 @@ module SemanticLogger
|
|
113
118
|
# Use SemanticLogger.add_appender and SemanticLogger.remove_appender
|
114
119
|
# to manipulate the active appenders list
|
115
120
|
def self.appenders
|
116
|
-
@@appenders.
|
121
|
+
@@appenders.clone
|
117
122
|
end
|
118
123
|
|
119
124
|
# Wait until all queued log messages have been written and flush all active
|
@@ -128,12 +133,14 @@ module SemanticLogger
|
|
128
133
|
# Note: Only appenders that implement the reopen method will be called
|
129
134
|
def self.reopen
|
130
135
|
@@appenders.each {|appender| appender.reopen if appender.respond_to?(:reopen)}
|
136
|
+
# After a fork the appender thread is not running, start it if it is not running
|
137
|
+
SemanticLogger::Logger.start_appender_thread
|
131
138
|
end
|
132
139
|
|
133
140
|
############################################################################
|
134
141
|
protected
|
135
142
|
|
136
|
-
@@appenders
|
143
|
+
@@appenders = ThreadSafe::Array.new
|
137
144
|
|
138
145
|
############################################################################
|
139
146
|
private
|
data/test/logger_test.rb
CHANGED
@@ -38,9 +38,9 @@ class LoggerTest < Test::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context "
|
41
|
+
context "tagged logging" do
|
42
42
|
should "add tags to log entries" do
|
43
|
-
@logger.
|
43
|
+
@logger.tagged('12345', 'DJHSFK') do
|
44
44
|
@logger.info('Hello world')
|
45
45
|
SemanticLogger.flush
|
46
46
|
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \[12345\] \[DJHSFK\] LoggerTest -- Hello world/, @mock_logger.message
|
@@ -48,8 +48,8 @@ class LoggerTest < Test::Unit::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
should "add embedded tags to log entries" do
|
51
|
-
@logger.
|
52
|
-
@logger.
|
51
|
+
@logger.tagged('First Level', 'tags') do
|
52
|
+
@logger.tagged('Second Level') do
|
53
53
|
@logger.info('Hello world')
|
54
54
|
SemanticLogger.flush
|
55
55
|
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \[First Level\] \[tags\] \[Second Level\] LoggerTest -- Hello world/, @mock_logger.message
|
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.
|
4
|
+
version: 2.6.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: 2013-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sync_attr
|
@@ -68,7 +68,7 @@ files:
|
|
68
68
|
- test/loggable_test.rb
|
69
69
|
- test/logger_test.rb
|
70
70
|
- test/mock_logger.rb
|
71
|
-
homepage: https://github.com/
|
71
|
+
homepage: https://github.com/reidmorrison/semantic_logger
|
72
72
|
licenses:
|
73
73
|
- Apache License V2.0
|
74
74
|
metadata: {}
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.1.11
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Improved logging for Ruby
|