rails_semantic_logger 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -524
- data/lib/rails_semantic_logger/railtie.rb +1 -1
- data/lib/rails_semantic_logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b40941e0afc3473dcbd06969af45d8a9f6ff47d
|
4
|
+
data.tar.gz: 34897336d250e32a0df5be64f2600c831b5a05ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa352a01ab7dc1431a1e328192a32730c56390fd60234bbe3ed0b237f391dc94bd42c3f5f93f9177478798009f1897b4bc0558e25ce49e6cb5ccc166adcb960
|
7
|
+
data.tar.gz: b5e0a96ff4d1a3a9187b7879263af9606349cc9ee442c6cb843d377657e081df562995f84a168573e1ea3bfc5c54f300de6c90bf620de9a57e8954f204995043
|
data/README.md
CHANGED
@@ -1,533 +1,22 @@
|
|
1
1
|
rails_semantic_logger
|
2
2
|
=====================
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
* http://github.com/reidmorrison/rails_semantic_logger
|
7
|
-
|
8
|
-
## Overview
|
4
|
+
Next generation logging system for Rails to support highly concurrent, high throughput, low latency systems
|
9
5
|
|
10
6
|
Rails Semantic Logger replaces the Rails default logger with [Semantic Logger](http://github.com/reidmorrison/semantic_logger)
|
11
7
|
|
12
|
-
|
13
|
-
logging in Ruby to a new level by adding several new capabilities to the
|
14
|
-
commonly used Logging API:
|
15
|
-
|
16
|
-
Dynamic
|
17
|
-
|
18
|
-
* Increase the log level at runtime for just one class
|
19
|
-
* For example enable debug level logging for a single class (logging instance)
|
20
|
-
while the program is running to get more detailed logging in production for just that class
|
21
|
-
|
22
|
-
Tagged Logging
|
23
|
-
|
24
|
-
* Supply custom data to be added to every log entry within a block of code,
|
25
|
-
including libraries and existing gems
|
26
|
-
* Tagged logging is critical for any high traffic site so that one can narrow
|
27
|
-
down log entries for a single call that is mixed in with log entries
|
28
|
-
from hundreds of other log entries
|
29
|
-
|
30
|
-
High Performance
|
31
|
-
|
32
|
-
* Logging is performed in a separate thread so as not to impact performance of
|
33
|
-
running code
|
34
|
-
|
35
|
-
Customizable
|
36
|
-
|
37
|
-
* Custom formatting by destination
|
38
|
-
* Easy to "roll your own" destination (Appender).
|
39
|
-
For example to log to Hadoop, Redis, etc..
|
40
|
-
|
41
|
-
Payload support
|
42
|
-
|
43
|
-
* Aside from the regular log message, a hash payload can also be supplied with
|
44
|
-
every log entry
|
45
|
-
* Very powerful when logging to NOSQL destinations that allow queries against
|
46
|
-
any data in the payload
|
47
|
-
|
48
|
-
Exceptions
|
49
|
-
|
50
|
-
* Directly log exceptions
|
51
|
-
* Semantic Logger standardizes the logging of exceptions with their backtraces
|
52
|
-
to text destinations and writes the exception elements as a hash to NOSQL
|
53
|
-
destinations
|
54
|
-
|
55
|
-
Drop-in Replacement
|
56
|
-
|
57
|
-
* Simple drop-in replacement for the Ruby, or the Rails loggers
|
58
|
-
* Supports current common logging interface
|
59
|
-
* No changes to existing to code to use new logger ( other than replacing the logger )
|
60
|
-
|
61
|
-
Rails 2, 3 & 4 Support
|
62
|
-
|
63
|
-
* Just include the semantic_logger gem into Rails and it will immediately
|
64
|
-
replace the existing loggers to improve performance and information
|
65
|
-
in the log files
|
66
|
-
* The Rails 3 Tagged logging feature is already available for Rails 2 by using Semantic Logger
|
67
|
-
* Rails 4 push_tags and pop_tags methods are supported
|
68
|
-
|
69
|
-
Thread Aware
|
70
|
-
|
71
|
-
* Includes the process and thread id information in every log entry
|
72
|
-
* If running JRuby it will also include the name of the thread for every log entry
|
73
|
-
|
74
|
-
Trace Level
|
75
|
-
|
76
|
-
* :trace is a new level common in other languages and is commonly used for
|
77
|
-
logging trace level detail. It is intended for logging data at level below
|
78
|
-
:debug.
|
79
|
-
* :trace can be used for logging the actual data sent or received over the network
|
80
|
-
that is rarely needed but is critical when things are not working as expected.
|
81
|
-
* Since :trace can be enabled on a per class basis it can even be turned on
|
82
|
-
in production to resolve what was actually sent to an external vendor
|
83
|
-
|
84
|
-
Multiple Destinations
|
85
|
-
|
86
|
-
* Log to multiple destinations at the same time ( File and MongoDB, etc.. )
|
87
|
-
* Each destination can also have its own log level.
|
88
|
-
For example, only log :info and above to MongoDB, or :warn and above to a
|
89
|
-
second log file
|
90
|
-
|
91
|
-
Benchmarking
|
92
|
-
|
93
|
-
* The performance of any block of code can be measured and logged at the same time
|
94
|
-
depending on the active log level
|
95
|
-
|
96
|
-
Semantic Capabilities
|
97
|
-
|
98
|
-
* With Semantic Logger it is simple to mix-in additional semantic information with
|
99
|
-
every log entry
|
100
|
-
* The application or class name is automatically included for every log entry under
|
101
|
-
a specific logging instance
|
102
|
-
* Includes the duration of blocks of code
|
103
|
-
* Any hash containing context specific information such as user_id or location information
|
104
|
-
|
105
|
-
Beyond Tagged Logging
|
106
|
-
|
107
|
-
* Supply entire hash of custom data to be added to the payload of every log entry
|
108
|
-
within a block of code, including libraries and existing gems
|
109
|
-
|
110
|
-
NOSQL Destinations
|
111
|
-
|
112
|
-
* Every log entry is broken down into elements that NOSQL data stores can understand:
|
113
|
-
|
114
|
-
```json
|
115
|
-
{
|
116
|
-
"_id" : ObjectId("5034fa48e3f3fea945e83ef2"),
|
117
|
-
"time" : ISODate("2012-08-22T15:27:04.409Z"),
|
118
|
-
"host_name" : "release",
|
119
|
-
"pid" : 16112,
|
120
|
-
"thread_name" : "main",
|
121
|
-
"name" : "UserLocator",
|
122
|
-
"level" : "debug",
|
123
|
-
"message" : "Fetch user information",
|
124
|
-
"duration" : 12,
|
125
|
-
"payload" : {
|
126
|
-
"user" : "Jack",
|
127
|
-
"zip_code" : 12345,
|
128
|
-
"location" : "US"
|
129
|
-
}
|
130
|
-
}
|
131
|
-
```
|
132
|
-
|
133
|
-
Thread Safe
|
134
|
-
|
135
|
-
* Semantic Logger is completely thread safe and all methods can be called
|
136
|
-
concurrently from any thread
|
137
|
-
* Tagged logging keeps any tagging data on a per-thread basis to ensure that
|
138
|
-
tags from different threads are not inter-mingled
|
139
|
-
|
140
|
-
## Introduction
|
141
|
-
|
142
|
-
Just by including the rails_semantic_logger gem, Rails Semantic Logger will
|
143
|
-
replace the default Rails logger with Semantic Logger. Without further
|
144
|
-
configuration it will log to the existing Rails log file in a more efficient
|
145
|
-
multi-threaded way.
|
146
|
-
|
147
|
-
Extract from a Rails log file after adding the semantic_logger gem:
|
148
|
-
|
149
|
-
```
|
150
|
-
2012-10-19 12:05:46.736 I [35940:JRubyWorker-10] Rails --
|
151
|
-
|
152
|
-
Started GET "/" for 127.0.0.1 at 2012-10-19 12:05:46 +0000
|
153
|
-
2012-10-19 12:05:47.318 I [35940:JRubyWorker-10] ActionController -- Processing by AdminController#index as HTML
|
154
|
-
2012-10-19 12:05:47.633 D [35940:JRubyWorker-10] ActiveRecord -- User Load (2.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
|
155
|
-
2012-10-19 12:05:49.833 D [35940:JRubyWorker-10] ActiveRecord -- Role Load (2.0ms) SELECT `roles`.* FROM `roles`
|
156
|
-
2012-10-19 12:05:49.868 D [35940:JRubyWorker-10] ActiveRecord -- Role Load (1.0ms) SELECT * FROM `roles` INNER JOIN `roles_users` ON `roles`.id = `roles_users`.role_id WHERE (`roles_users`.user_id = 1 )
|
157
|
-
2012-10-19 12:05:49.885 I [35940:JRubyWorker-10] ActionController -- Rendered menus/_control_system.html.erb (98.0ms)
|
158
|
-
2012-10-19 12:05:51.014 I [35940:JRubyWorker-10] ActionController -- Rendered layouts/_top_bar.html.erb (386.0ms)
|
159
|
-
2012-10-19 12:05:51.071 D [35940:JRubyWorker-10] ActiveRecord -- Announcement Load (20.0ms) SELECT `announcements`.* FROM `announcements` WHERE `announcements`.`active` = 1 ORDER BY created_at desc
|
160
|
-
2012-10-19 12:05:51.072 I [35940:JRubyWorker-10] ActionController -- Rendered layouts/_announcement.html.erb (26.0ms)
|
161
|
-
2012-10-19 12:05:51.083 I [35940:JRubyWorker-10] ActionController -- Rendered layouts/_flash.html.erb (4.0ms)
|
162
|
-
2012-10-19 12:05:51.109 I [35940:JRubyWorker-10] ActionController -- Rendered layouts/_footer.html.erb (16.0ms)
|
163
|
-
2012-10-19 12:05:51.109 I [35940:JRubyWorker-10] ActionController -- Rendered admin/index.html.erb within layouts/base (1329.0ms)
|
164
|
-
2012-10-19 12:05:51.113 I [35940:JRubyWorker-10] ActionController -- Completed 200 OK in 3795ms (Views: 1349.0ms | ActiveRecord: 88.0ms | Mongo: 0.0ms)
|
165
|
-
```
|
166
|
-
|
167
|
-
## Logging API
|
168
|
-
|
169
|
-
### Standard Logging methods
|
170
|
-
|
171
|
-
The Semantic Logger logging API supports the existing logging interface for
|
172
|
-
the Rails and Ruby Loggers. For example:
|
173
|
-
|
174
|
-
```ruby
|
175
|
-
logger.info("Hello World")
|
176
|
-
```
|
177
|
-
|
178
|
-
Or to query whether a specific log level is set
|
179
|
-
|
180
|
-
```ruby
|
181
|
-
logger.info?
|
182
|
-
```
|
183
|
-
|
184
|
-
The following logging methods are available
|
185
|
-
|
186
|
-
```ruby
|
187
|
-
trace(message, payload=nil, exception=nil, &block)
|
188
|
-
debug(message, payload=nil, exception=nil, &block)
|
189
|
-
info(message, payload=nil, exception=nil, &block)
|
190
|
-
warn(message, payload=nil, exception=nil, &block)
|
191
|
-
error(message, payload=nil, exception=nil, &block)
|
192
|
-
fatal(message, payload=nil, exception=nil, &block)
|
193
|
-
```
|
194
|
-
|
195
|
-
Parameters
|
196
|
-
|
197
|
-
- message: The text message to log.
|
198
|
-
Mandatory only if no block is supplied
|
199
|
-
- payload: Optional, either a Ruby Exception object or a Hash
|
200
|
-
- exception: Optional, Ruby Exception object. Allows both an exception and a payload to be logged
|
201
|
-
- block: The optional block is executed only if the corresponding log level
|
202
|
-
is active. Can be used to prevent unnecessary calculations of debug data in
|
203
|
-
production.
|
204
|
-
|
205
|
-
Examples:
|
206
|
-
|
207
|
-
```ruby
|
208
|
-
logger.debug("Calling Supplier")
|
209
|
-
|
210
|
-
logger.debug("Calling Supplier", :request => 'update', :user => 'Jack')
|
211
|
-
|
212
|
-
logger.debug { "A total of #{result.inject(0) {|sum, i| i+sum }} were processed" }
|
213
|
-
```
|
214
|
-
|
215
|
-
## Exceptions
|
216
|
-
|
217
|
-
The Semantic Logger adds an optional parameter to the existing log methods so that
|
218
|
-
a corresponding Exception can be logged in a standard way
|
219
|
-
|
220
|
-
```ruby
|
221
|
-
begin
|
222
|
-
# ... Code that can raise an exception
|
223
|
-
rescue Exception => exception
|
224
|
-
logger.error("Oops external call failed", exception)
|
225
|
-
# Re-raise or handle the exception
|
226
|
-
raise exception
|
227
|
-
end
|
228
|
-
```
|
229
|
-
|
230
|
-
### Payload
|
231
|
-
|
232
|
-
The Semantic Logger adds an extra parameter to the existing log methods so that
|
233
|
-
additional payload can be logged, such as a Hash or a Ruby Exception object.
|
234
|
-
|
235
|
-
```ruby
|
236
|
-
logger.info("Oops external call failed", :result => :failed, :reason_code => -10)
|
237
|
-
```
|
238
|
-
|
239
|
-
The additional payload is machine readable so that we don't have to write complex
|
240
|
-
regular expressions so that a program can analyze log output. With the MongoDB
|
241
|
-
appender the payload is written directly to MongoDB as part of the document and
|
242
|
-
is therefore fully searchable
|
243
|
-
|
244
|
-
### Benchmarking
|
245
|
-
|
246
|
-
Another common logging requirement is to measure the time it takes to execute a block
|
247
|
-
of code based on the log level. For example:
|
248
|
-
|
249
|
-
```ruby
|
250
|
-
Rails.logger.benchmark_info "Calling external interface" do
|
251
|
-
# Code to call external service ...
|
252
|
-
end
|
253
|
-
```
|
254
|
-
|
255
|
-
The following output will be written to file:
|
256
|
-
|
257
|
-
2012-08-30 15:37:29.474 I [48308:ScriptThreadProcess: script/rails] (5.2ms) Rails -- Calling external interface
|
258
|
-
|
259
|
-
If an exception is raised during the block the exception is logged
|
260
|
-
at the same log level as the benchmark along with the duration and message.
|
261
|
-
The exception will flow through to the caller unchanged
|
262
|
-
|
263
|
-
The following benchmarking methods are available
|
264
|
-
|
265
|
-
```ruby
|
266
|
-
benchmark_trace(message, params=nil, &block)
|
267
|
-
benchmark_debug(message, params=nil, &block)
|
268
|
-
benchmark_info(message, params=nil, &block)
|
269
|
-
benchmark_warn(message, params=nil, &block)
|
270
|
-
benchmark_error(message, params=nil, &block)
|
271
|
-
benchmark_fatal(message, params=nil, &block)
|
272
|
-
```
|
273
|
-
|
274
|
-
Parameters
|
275
|
-
|
276
|
-
- message: The mandatory text message to log.
|
277
|
-
- params:
|
278
|
-
```
|
279
|
-
:log_exception
|
280
|
-
Control whether or how an exception thrown in the block is
|
281
|
-
reported by Semantic Logger. Values:
|
282
|
-
:full
|
283
|
-
Log the exception class, message, and backtrace
|
284
|
-
:partial
|
285
|
-
Log the exception class and messag
|
286
|
-
The backtrace will not be logged
|
287
|
-
:off
|
288
|
-
Any unhandled exception from the block will not be logged
|
289
|
-
|
290
|
-
:min_duration
|
291
|
-
Only log if the block takes longer than this duration in ms
|
292
|
-
Default: 0.0
|
293
|
-
|
294
|
-
:payload
|
295
|
-
Optional, Hash payload
|
296
|
-
|
297
|
-
:exception
|
298
|
-
Optional, Ruby Exception object to log along with the duration of the supplied block
|
299
|
-
```
|
300
|
-
|
301
|
-
### Logging levels
|
302
|
-
|
303
|
-
The following logging levels are available through Semantic Logger
|
304
|
-
|
305
|
-
:trace, :debug, :info, :warn, :error, :fatal
|
306
|
-
|
307
|
-
The log levels are listed above in the order of precedence with the most detail to the least.
|
308
|
-
For example :debug would include :info, :warn, :error, :fatal levels but not :trace
|
309
|
-
And :fatal would only log :fatal error messages and nothing else
|
310
|
-
|
311
|
-
:unknown has been mapped to :fatal for Rails and Ruby Logger
|
312
|
-
|
313
|
-
:trace is a new level that is often used for tracing low level calls such
|
314
|
-
as the data sent or received to external web services. It is also commonly used
|
315
|
-
in the development environment for low level trace logging of methods calls etc.
|
316
|
-
|
317
|
-
If only the rails logger is being used, then :trace level calls will be logged
|
318
|
-
as debug calls only if the log level is set to trace
|
319
|
-
|
320
|
-
### Changing the Class name for Log Entries
|
321
|
-
|
322
|
-
When Semantic Logger is included in a Rails project it automatically replaces the
|
323
|
-
loggers for Rails, ActiveRecord::Base, ActionController::Base, and ActiveResource::Base
|
324
|
-
with wrappers that set their Class name. For example:
|
325
|
-
|
326
|
-
```ruby
|
327
|
-
ActiveRecord::Base.logger = SemanticLogger::Logger.new(ActiveRecord)
|
328
|
-
```
|
329
|
-
|
330
|
-
By replacing their loggers we now get the class name in the text logging output:
|
331
|
-
|
332
|
-
2012-08-30 15:24:13.439 D [47900:main] ActiveRecord -- SQL (12.0ms) SELECT `schema_migrations`.`version` FROM `schema_migrations`
|
333
|
-
|
334
|
-
It is recommended to include a class specific logger for all major classes that will
|
335
|
-
be logging using the SemanticLogger::Loggable mix-in. For Example:
|
336
|
-
|
337
|
-
```ruby
|
338
|
-
require 'semantic_logger'
|
339
|
-
|
340
|
-
class ExternalSupplier
|
341
|
-
# Lazy load logger class variable on first use
|
342
|
-
include SemanticLogger::Loggable
|
343
|
-
|
344
|
-
def call_supplier(amount, name)
|
345
|
-
logger.debug "Calculating with amount", { :amount => amount, :name => name }
|
346
|
-
|
347
|
-
# Measure and log on completion how long the call took to the external supplier
|
348
|
-
logger.benchmark_info "Calling external interface" do
|
349
|
-
# Code to call the external supplier ...
|
350
|
-
end
|
351
|
-
end
|
352
|
-
end
|
353
|
-
```
|
354
|
-
|
355
|
-
This will result in the log output identifying the log entry as from the ExternalSupplier class
|
356
|
-
|
357
|
-
2012-08-30 15:37:29.474 I [48308:ScriptThreadProcess: script/rails] (5.2ms) ExternalSupplier -- Calling external interface
|
358
|
-
|
359
|
-
### Tagged Logging
|
360
|
-
|
361
|
-
Semantic Logger allows any Ruby or Rails program to also include tagged logging.
|
362
|
-
|
363
|
-
This means that any logging performed within a block, including any called
|
364
|
-
libraries or gems to include the specified tag with every log entry.
|
365
|
-
|
366
|
-
Using Tagged logging is critical in any highly concurrent environment so that
|
367
|
-
one can quickly find all related log entries across all levels of code, and even
|
368
|
-
across threads
|
369
|
-
|
370
|
-
```ruby
|
371
|
-
logger.tagged(tracking_number) do
|
372
|
-
logger.debug("Hello World")
|
373
|
-
# ...
|
374
|
-
end
|
375
|
-
```
|
376
|
-
|
377
|
-
### Beyond Tagged Logging
|
378
|
-
|
379
|
-
Blocks of code can be tagged with not only values, but can be tagged with
|
380
|
-
entire hashes of data. The additional hash of data will be merged into
|
381
|
-
the payload of every log entry
|
382
|
-
|
383
|
-
For example every corresponding log entry could include a hash containing
|
384
|
-
a user_id, name, region, zip_code, tracking_number, etc...
|
385
|
-
|
386
|
-
```ruby
|
387
|
-
logger.with_payload(:user => 'Jack', :zip_code => 12345) do
|
388
|
-
logger.debug("Hello World")
|
389
|
-
# ...
|
390
|
-
end
|
391
|
-
```
|
392
|
-
|
393
|
-
### Installation
|
394
|
-
|
395
|
-
Add the following line to Gemfile
|
396
|
-
|
397
|
-
```ruby
|
398
|
-
gem 'rails_semantic_logger'
|
399
|
-
```
|
400
|
-
|
401
|
-
Install required gems with bundler
|
402
|
-
|
403
|
-
bundle install
|
404
|
-
|
405
|
-
This will automatically replace the standard Rails logger with Semantic Logger
|
406
|
-
which will write all log data to the configured Rails logger.
|
407
|
-
|
408
|
-
### Configuration
|
409
|
-
|
410
|
-
By default Semantic Logger will detect the log level from Rails. To set the
|
411
|
-
log level explicitly, add the following line to
|
412
|
-
config/environments/production.rb inside the Application.configure block
|
413
|
-
|
414
|
-
```ruby
|
415
|
-
config.log_level = :trace
|
416
|
-
```
|
417
|
-
|
418
|
-
#### MongoDB logging
|
419
|
-
|
420
|
-
To log to both the Rails log file and MongoDB add the following lines to
|
421
|
-
config/environments/production.rb inside the Application.configure block
|
422
|
-
|
423
|
-
```ruby
|
424
|
-
config.after_initialize do
|
425
|
-
# Re-use the existing MongoDB connection, or create a new one here
|
426
|
-
db = Mongo::Connection.new['production_logging']
|
427
|
-
|
428
|
-
# Besides logging to the standard Rails logger, also log to MongoDB
|
429
|
-
config.semantic_logger.add_appender SemanticLogger::Appender::MongoDB.new(
|
430
|
-
:db => db,
|
431
|
-
:collection_name => 'semantic_logger',
|
432
|
-
:collection_size => 25.gigabytes
|
433
|
-
)
|
434
|
-
end
|
435
|
-
```
|
436
|
-
|
437
|
-
#### Logging to Syslog
|
438
|
-
|
439
|
-
Configuring rails to also log to a local Syslog:
|
440
|
-
```ruby
|
441
|
-
config.after_initialize do
|
442
|
-
config.semantic_logger.add_appender(SemanticLogger::Appender::Syslog.new)
|
443
|
-
end
|
444
|
-
```
|
445
|
-
|
446
|
-
Configuring rails to also log to a remote Syslog server such as syslog-ng over TCP:
|
447
|
-
```ruby
|
448
|
-
config.after_initialize do
|
449
|
-
config.semantic_logger.add_appender(SemanticLogger::Appender::Syslog.new(:server => 'tcp://myloghost:514'))
|
450
|
-
end
|
451
|
-
```
|
452
|
-
|
453
|
-
#### Colorized Logging
|
454
|
-
|
455
|
-
If the Rails colorized logging is enabled, then the colorized formatter will be used
|
456
|
-
by default. To disable colorized logging in both Rails and SemanticLogger:
|
457
|
-
|
458
|
-
```ruby
|
459
|
-
config.colorize_logging = false
|
460
|
-
```
|
461
|
-
|
462
|
-
## Custom Appenders and Formatters
|
463
|
-
|
464
|
-
The format of data logged by Semantic Logger is specific to each appender.
|
465
|
-
|
466
|
-
To change the text file log format in Rails SemanticLogger, create a rails initializer with the following code and customize as needed.
|
467
|
-
For example: 'config/initializers/semantic_logger_formatter.rb'
|
468
|
-
|
469
|
-
```ruby
|
470
|
-
# Replace the format of the existing log file appender
|
471
|
-
SemanticLogger.appenders.first.formatter = Proc.new do |log|
|
472
|
-
tags = log.tags.collect { |tag| "[#{tag}]" }.join(" ") + " " if log.tags && (log.tags.size > 0)
|
473
|
-
|
474
|
-
message = log.message.to_s
|
475
|
-
message << " -- " << log.payload.inspect if log.payload
|
476
|
-
message << " -- " << "#{log.exception.class}: #{log.exception.message}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception
|
477
|
-
|
478
|
-
duration_str = log.duration ? "(#{'%.1f' % log.duration}ms) " : ''
|
479
|
-
|
480
|
-
"#{SemanticLogger::Appender::Base.formatted_time(log.time)} #{log.level.to_s[0..0].upcase} [#{$$}:#{log.thread_name}] #{tags}#{duration_str}#{log.name} : #{message}"
|
481
|
-
end
|
482
|
-
```
|
483
|
-
|
484
|
-
To write your own appenders or formatting, see [SemanticLogger](http://github.com/reidmorrison/semantic_logger)
|
485
|
-
|
486
|
-
## Log Rotation
|
487
|
-
|
488
|
-
Since the log file is not re-opened with every call, when the log file needs
|
489
|
-
to be rotated, use a copy-truncate operation rather than deleting the file.
|
490
|
-
|
491
|
-
## Process Forking
|
492
|
-
|
493
|
-
The following frameworks are automatically detected when rails is configured
|
494
|
-
so that the necessary callbacks are registered to re-open appenders after a process fork:
|
495
|
-
|
496
|
-
- Phusion Passenger
|
497
|
-
- Resque
|
498
|
-
|
499
|
-
### Unicorn
|
500
|
-
|
501
|
-
With Unicorn, add the following code to you Unicorn configuration:
|
502
|
-
|
503
|
-
```ruby
|
504
|
-
# config/unicorn.conf.rb
|
505
|
-
after_fork do |server, worker|
|
506
|
-
# Re-open appenders after forking the process
|
507
|
-
SemanticLogger.reopen
|
508
|
-
end
|
509
|
-
```
|
510
|
-
|
511
|
-
### Puma
|
8
|
+
* http://github.com/reidmorrison/rails_semantic_logger
|
512
9
|
|
513
|
-
|
514
|
-
add the following to your worker boot code:
|
10
|
+
## Documentation
|
515
11
|
|
516
|
-
|
517
|
-
# config/puma.rb
|
518
|
-
on_worker_boot do
|
519
|
-
# Re-open appenders after forking the process
|
520
|
-
SemanticLogger.reopen
|
521
|
-
end
|
522
|
-
```
|
12
|
+
For complete documentation see: http://reidmorrison.github.io/semantic_logger/rails
|
523
13
|
|
524
14
|
## Dependencies
|
525
15
|
|
526
|
-
- Ruby
|
527
|
-
- Rails 2, 3, 4
|
16
|
+
- Ruby 1.8.7, 1.9.3, 2.0, 2.1 (and above) Or, JRuby 1.6.3 (or above)
|
17
|
+
- Rails 2, 3, 4 and above
|
528
18
|
|
529
|
-
Meta
|
530
|
-
----
|
19
|
+
## Meta
|
531
20
|
|
532
21
|
* Code: `git clone git://github.com/reidmorrison/rails_semantic_logger.git`
|
533
22
|
* Home: <https://github.com/reidmorrison/rails_semantic_logger>
|
@@ -536,18 +25,15 @@ Meta
|
|
536
25
|
|
537
26
|
This project uses [Semantic Versioning](http://semver.org/).
|
538
27
|
|
539
|
-
Author
|
540
|
-
------
|
28
|
+
## Author
|
541
29
|
|
542
30
|
Reid Morrison :: reidmo@gmail.com :: @reidmorrison
|
543
31
|
|
544
|
-
Contributors
|
545
|
-
------------
|
32
|
+
## Contributors
|
546
33
|
|
547
34
|
Marc Bellingrath :: marrrc.b@gmail.com
|
548
35
|
|
549
|
-
License
|
550
|
-
-------
|
36
|
+
## License
|
551
37
|
|
552
38
|
Copyright 2012, 2013, 2014 Reid Morrison
|
553
39
|
|
@@ -14,7 +14,7 @@ module RailsSemanticLogger #:nodoc:
|
|
14
14
|
# )
|
15
15
|
# end
|
16
16
|
# end
|
17
|
-
config.semantic_logger = ::SemanticLogger
|
17
|
+
config.semantic_logger = ::SemanticLogger
|
18
18
|
|
19
19
|
# Initialize SemanticLogger. In a Rails environment it will automatically
|
20
20
|
# insert itself above the configured rails logger to add support for its
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.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-
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: semantic_logger
|