semantic_logger 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +4 -0
- data/Rakefile +1 -0
- data/dev.log +18 -0
- data/lib/semantic_logger/logger.rb +56 -40
- data/lib/semantic_logger/version.rb +1 -1
- data/semantic_logger-0.7.1.gem +0 -0
- metadata +22 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,6 +5,7 @@ GEM
|
|
5
5
|
i18n (~> 0.6)
|
6
6
|
multi_json (~> 1.0)
|
7
7
|
bson (1.7.0)
|
8
|
+
bson (1.7.0-java)
|
8
9
|
bson_ext (1.7.0)
|
9
10
|
bson (~> 1.7.0)
|
10
11
|
i18n (0.6.1)
|
@@ -18,8 +19,10 @@ GEM
|
|
18
19
|
shoulda-matchers (1.4.0)
|
19
20
|
activesupport (>= 3.0.0)
|
20
21
|
sync_attr (0.1.1)
|
22
|
+
thread_safe (0.0.3)
|
21
23
|
|
22
24
|
PLATFORMS
|
25
|
+
java
|
23
26
|
ruby
|
24
27
|
|
25
28
|
DEPENDENCIES
|
@@ -27,3 +30,4 @@ DEPENDENCIES
|
|
27
30
|
mongo
|
28
31
|
shoulda
|
29
32
|
sync_attr
|
33
|
+
thread_safe
|
data/Rakefile
CHANGED
@@ -22,6 +22,7 @@ task :gem do |t|
|
|
22
22
|
spec.files = FileList["./**/*"].exclude('*.gem', 'nbproject').map{|f| f.sub(/^\.\//, '')}
|
23
23
|
spec.has_rdoc = true
|
24
24
|
spec.add_dependency 'sync_attr'
|
25
|
+
spec.add_dependency 'thread_safe'
|
25
26
|
spec.add_development_dependency 'shoulda'
|
26
27
|
end
|
27
28
|
Gem::Builder.new(gemspec).build
|
data/dev.log
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
2012-10-18 13:34:41.198757 D [95128:70168596413880] SemanticLogger::Appender::File -- SemanticLogger::Logger Appender thread started
|
2
|
+
2012-10-18 13:34:41.202210 T [95128:70168592210640] Hello -- Trace this
|
3
|
+
2012-10-18 13:34:41.203420 T [95128:70168592210640] Hello -- Trace After
|
4
|
+
2012-10-18 13:35:03.207898 D [95128:70168592210640] SemanticLogger::Appender::File -- SemanticLogger::Logger process terminating, flushing appenders
|
5
|
+
2012-10-18 13:35:03.208132 D [95128:70168596413880] SemanticLogger::Appender::File -- SemanticLogger::Logger appenders flushed
|
6
|
+
2012-10-18 13:35:03.226551 D [95128:70168596413880] SemanticLogger::Appender::File -- SemanticLogger::Logger Appender thread stopped
|
7
|
+
2012-10-18 13:35:16.375653 D [95296:70233482947260] SemanticLogger::Appender::File -- SemanticLogger::Logger Appender thread started
|
8
|
+
2012-10-18 13:35:16.380396 T [95296:70233482287840] Hello -- Trace this
|
9
|
+
2012-10-18 13:35:16.381089 T [95296:70233482287840] Hello -- Trace After
|
10
|
+
2012-10-18 13:35:21.767557 D [95296:70233482287840] SemanticLogger::Appender::File -- SemanticLogger::Logger process terminating, flushing appenders
|
11
|
+
2012-10-18 13:35:21.767813 D [95296:70233482947260] SemanticLogger::Appender::File -- SemanticLogger::Logger appenders flushed
|
12
|
+
2012-10-18 13:35:21.769090 D [95296:70233482947260] SemanticLogger::Appender::File -- SemanticLogger::Logger Appender thread stopped
|
13
|
+
2012-10-18 13:35:49.755489 D [95301:70263790953920] SemanticLogger::Appender::File -- SemanticLogger::Logger Appender thread started
|
14
|
+
2012-10-18 13:35:58.251090 T [95301:70263790328540] Hello -- Trace this
|
15
|
+
2012-10-18 13:35:58.252585 T [95301:70263790328540] Hello -- Trace After
|
16
|
+
2012-10-18 13:36:08.710232 D [95301:70263790328540] SemanticLogger::Appender::File -- SemanticLogger::Logger process terminating, flushing appenders
|
17
|
+
2012-10-18 13:36:08.711053 D [95301:70263790953920] SemanticLogger::Appender::File -- SemanticLogger::Logger appenders flushed
|
18
|
+
2012-10-18 13:36:08.712175 D [95301:70263790953920] SemanticLogger::Appender::File -- SemanticLogger::Logger Appender thread stopped
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'thread'
|
2
|
+
require 'thread_safe'
|
2
3
|
require 'sync_attr'
|
3
4
|
|
4
5
|
# Logger is the interface used by
|
@@ -36,9 +37,14 @@ module SemanticLogger
|
|
36
37
|
class Logger < Base
|
37
38
|
include SyncAttr
|
38
39
|
|
39
|
-
#
|
40
|
-
|
41
|
-
|
40
|
+
# Add or remove logging appenders to the appenders Array
|
41
|
+
# Appenders will be written to in the order that they appear in this list
|
42
|
+
sync_cattr_reader :appenders do
|
43
|
+
# The logging thread is only started once an appender has been defined
|
44
|
+
startup
|
45
|
+
|
46
|
+
# Thread safe appenders array
|
47
|
+
ThreadSafe::Array.new
|
42
48
|
end
|
43
49
|
|
44
50
|
# Initial default Level for all new instances of SemanticLogger::Logger
|
@@ -90,17 +96,17 @@ module SemanticLogger
|
|
90
96
|
queue.size
|
91
97
|
end
|
92
98
|
|
93
|
-
# Flush all
|
94
|
-
# All
|
99
|
+
# Flush all queued log entries disk, database, etc.
|
100
|
+
# All queued log messages are written and then each appender is flushed in turn
|
95
101
|
def self.flush
|
96
|
-
return false unless
|
102
|
+
return false unless started?
|
97
103
|
|
98
104
|
reply_queue = Queue.new
|
99
105
|
queue << { :command => :flush, :reply_queue => reply_queue }
|
100
106
|
reply_queue.pop
|
101
107
|
end
|
102
108
|
|
103
|
-
@@lag_check_interval =
|
109
|
+
@@lag_check_interval = 5000
|
104
110
|
@@lag_threshold_s = 30
|
105
111
|
|
106
112
|
# Returns the check_interval which is the number of messages between checks
|
@@ -125,13 +131,25 @@ module SemanticLogger
|
|
125
131
|
@@lag_threshold_s = time_threshold_s
|
126
132
|
end
|
127
133
|
|
134
|
+
# Returns whether the logging thread has been started
|
135
|
+
def self.started?
|
136
|
+
defined? :@@appenders
|
137
|
+
end
|
138
|
+
|
128
139
|
############################################################################
|
129
140
|
protected
|
130
141
|
|
142
|
+
@@queue = Queue.new
|
143
|
+
|
144
|
+
# Queue to hold messages that need to be logged to the various appenders
|
145
|
+
def self.queue
|
146
|
+
@@queue
|
147
|
+
end
|
148
|
+
|
131
149
|
# Place log request on the queue for the Appender thread to write to each
|
132
150
|
# appender in the order that they were registered
|
133
151
|
def log(log)
|
134
|
-
self.class.queue << log
|
152
|
+
self.class.queue << log if self.class.started?
|
135
153
|
end
|
136
154
|
|
137
155
|
# Internal logger for SemanticLogger
|
@@ -146,24 +164,27 @@ module SemanticLogger
|
|
146
164
|
SemanticLogger::Appender::File.new(STDERR, :warn)
|
147
165
|
end
|
148
166
|
|
149
|
-
# Log to queue
|
150
|
-
# Starts the appender thread the first time a logging call is made
|
151
|
-
sync_cattr_reader :queue do
|
152
|
-
startup
|
153
|
-
at_exit { shutdown }
|
154
|
-
Queue.new
|
155
|
-
end
|
156
|
-
|
157
167
|
# Start a separate appender thread responsible for reading log messages and
|
158
168
|
# calling the appenders in it's thread
|
159
169
|
def self.startup
|
160
|
-
|
170
|
+
# This thread is designed to never go down unless the main thread terminates
|
171
|
+
# Before terminating at_exit is used to flush all the appenders
|
172
|
+
#
|
173
|
+
# Should any appender fail to log or flush, the exception is logged and
|
174
|
+
# other appenders will still be called
|
175
|
+
Thread.new do
|
176
|
+
logger.debug "SemanticLogger::Logger Appender thread started"
|
161
177
|
begin
|
162
|
-
logger.debug "SemanticLogger::Logger Appender thread started"
|
163
178
|
count = 0
|
164
179
|
while message = queue.pop
|
165
180
|
if message.is_a? Log
|
166
|
-
appenders.each
|
181
|
+
appenders.each do |appender|
|
182
|
+
begin
|
183
|
+
appender.log(message)
|
184
|
+
rescue Exception => exc
|
185
|
+
logger.error "SemanticLogger::Logger Appender thread: Failed to log to appender: #{appender.inspect}", exc
|
186
|
+
end
|
187
|
+
end
|
167
188
|
count += 1
|
168
189
|
# Check every few log messages whether this appender thread is falling behind
|
169
190
|
if count > lag_check_interval
|
@@ -174,39 +195,34 @@ module SemanticLogger
|
|
174
195
|
end
|
175
196
|
else
|
176
197
|
case message[:command]
|
177
|
-
when :shutdown
|
178
|
-
appenders.each {|appender| appender.flush }
|
179
|
-
message[:reply_queue] << true if message[:reply_queue]
|
180
|
-
logger.debug "SemanticLogger::Logger appenders flushed, now shutting down"
|
181
|
-
break
|
182
198
|
when :flush
|
183
|
-
appenders.each
|
199
|
+
appenders.each do |appender|
|
200
|
+
begin
|
201
|
+
appender.flush
|
202
|
+
rescue Exception => exc
|
203
|
+
logger.error "SemanticLogger::Logger Appender thread: Failed to flush appender: #{appender.inspect}", exc
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
184
207
|
message[:reply_queue] << true if message[:reply_queue]
|
185
208
|
logger.debug "SemanticLogger::Logger appenders flushed"
|
209
|
+
else
|
210
|
+
logger.warn "SemanticLogger::Logger Appender thread: Ignoring unknown command: #{message[:command]}"
|
186
211
|
end
|
187
212
|
end
|
188
213
|
end
|
189
214
|
rescue Exception => exception
|
190
|
-
logger.error "SemanticLogger::Logger Appender thread restarting due to exception
|
191
|
-
|
192
|
-
startup
|
215
|
+
logger.error "SemanticLogger::Logger Appender thread restarting due to exception", exception
|
216
|
+
retry
|
193
217
|
ensure
|
194
218
|
logger.debug "SemanticLogger::Logger Appender thread stopped"
|
195
219
|
end
|
196
220
|
end
|
197
|
-
end
|
198
221
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
logger.debug "SemanticLogger::Logger Shutdown. Stopping appender thread"
|
204
|
-
queue << { :command => :shutdown }
|
205
|
-
@@appender_thread.join
|
206
|
-
# Undefine the class variable for the queue since in test environments
|
207
|
-
# at_exit can be invoked multiple times
|
208
|
-
remove_class_variable(:@@queue)
|
209
|
-
true
|
222
|
+
at_exit do
|
223
|
+
logger.debug "SemanticLogger::Logger process terminating, flushing appenders"
|
224
|
+
flush
|
225
|
+
end
|
210
226
|
end
|
211
227
|
|
212
228
|
# Formatting does not occur within this thread, it is done by each appender
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sync_attr
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: thread_safe
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: shoulda
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,6 +67,7 @@ executables: []
|
|
51
67
|
extensions: []
|
52
68
|
extra_rdoc_files: []
|
53
69
|
files:
|
70
|
+
- dev.log
|
54
71
|
- FUTURE.rb
|
55
72
|
- Gemfile
|
56
73
|
- Gemfile.lock
|
@@ -73,6 +90,8 @@ files:
|
|
73
90
|
- Rakefile
|
74
91
|
- README.md
|
75
92
|
- semantic_logger-0.7.0.gem
|
93
|
+
- semantic_logger-0.7.1.gem
|
94
|
+
- semantic_logger-0.8.0.gem
|
76
95
|
- test/appender_file_test.rb
|
77
96
|
- test/appender_mongodb_test.rb
|
78
97
|
- test/appender_wrapper_test.rb
|
@@ -92,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
111
|
version: '0'
|
93
112
|
segments:
|
94
113
|
- 0
|
95
|
-
hash:
|
114
|
+
hash: 3275873948644639479
|
96
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
116
|
none: false
|
98
117
|
requirements:
|