rails_semantic_logger 1.2.1 → 1.3.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: 216cf8051bfdd1959cecd75b027786a93af2c01c
4
- data.tar.gz: 51c149aaceab989a1520d6c162d09f3127594d82
3
+ metadata.gz: 68749e4169b35e0a3200129e876af2421ae58b29
4
+ data.tar.gz: 72ca518fee4f3aa1fbde17905ca18b14d30f7ff3
5
5
  SHA512:
6
- metadata.gz: 422d398ffe68bfecf030d99537f50a033c715d5aba1ce981ee7d91821861aa9c981ecccf410e0e0fa98fc6a28e41e856b5ca713b8cbee46c3b9575a0a2ddfa92
7
- data.tar.gz: 1e9a705c6b9937f8273735e5d0c16e96362301d8e4204ccc6e35ec9515548e20306f649da6bb5cc5463efabe886bbcd449ff514816c3785e2ee3581aebeb692b
6
+ metadata.gz: aaad3ae9eadf26eaa45fda6adc2db46558615102a9861f369054738e16f327fa024559dce72e3c6b4667a14fe2a9612b3a016fc23aef2ca5d0bbf7bc4a462fec
7
+ data.tar.gz: 9d2c103e76dfe98f8604fdc4d641018c83b11dfafea17d0864544308ab250ff0860cff9b4a24811249bc8ced279b27d629490eaf16e5334b9b9b1fb23f98e8c0
@@ -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 Clarity Services, Inc.
189
+ Copyright 2012, 2013, 2014 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
@@ -3,13 +3,13 @@ rails_semantic_logger
3
3
 
4
4
  Improved logging for Ruby on Rails
5
5
 
6
- * http://github.com/ClarityServices/rails_semantic_logger
6
+ * http://github.com/reidmorrison/rails_semantic_logger
7
7
 
8
- ### Overview
8
+ ## Overview
9
9
 
10
- Rails Semantic Logger replaces the Rails default logger with [Semantic Logger](http://github.com/ClarityServices/semantic_logger)
10
+ Rails Semantic Logger replaces the Rails default logger with [Semantic Logger](http://github.com/reidmorrison/semantic_logger)
11
11
 
12
- [Semantic Logger](http://github.com/ClarityServices/semantic_logger) takes
12
+ [Semantic Logger](http://github.com/reidmorrison/semantic_logger) takes
13
13
  logging in Ruby to a new level by adding several new capabilities to the
14
14
  commonly used Logging API:
15
15
 
@@ -137,7 +137,7 @@ Thread Safe
137
137
  * Tagged logging keeps any tagging data on a per-thread basis to ensure that
138
138
  tags from different threads are not inter-mingled
139
139
 
140
- ### Introduction
140
+ ## Introduction
141
141
 
142
142
  Just by including the rails_semantic_logger gem, Rails Semantic Logger will
143
143
  replace the default Rails logger with Semantic Logger. Without further
@@ -164,9 +164,9 @@ Started GET "/" for 127.0.0.1 at 2012-10-19 12:05:46 +0000
164
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
165
  ```
166
166
 
167
- ### Logging API
167
+ ## Logging API
168
168
 
169
- #### Standard Logging methods
169
+ ### Standard Logging methods
170
170
 
171
171
  The Semantic Logger logging API supports the existing logging interface for
172
172
  the Rails and Ruby Loggers. For example:
@@ -212,7 +212,7 @@ logger.debug("Calling Supplier", :request => 'update', :user => 'Jack')
212
212
  logger.debug { "A total of #{result.inject(0) {|sum, i| i+sum }} were processed" }
213
213
  ```
214
214
 
215
- ### Exceptions
215
+ ## Exceptions
216
216
 
217
217
  The Semantic Logger adds an optional parameter to the existing log methods so that
218
218
  a corresponding Exception can be logged in a standard way
@@ -227,7 +227,7 @@ rescue Exception => exception
227
227
  end
228
228
  ```
229
229
 
230
- #### Payload
230
+ ### Payload
231
231
 
232
232
  The Semantic Logger adds an extra parameter to the existing log methods so that
233
233
  additional payload can be logged, such as a Hash or a Ruby Exception object.
@@ -241,7 +241,7 @@ regular expressions so that a program can analyze log output. With the MongoDB
241
241
  appender the payload is written directly to MongoDB as part of the document and
242
242
  is therefore fully searchable
243
243
 
244
- #### Benchmarking
244
+ ### Benchmarking
245
245
 
246
246
  Another common logging requirement is to measure the time it takes to execute a block
247
247
  of code based on the log level. For example:
@@ -298,7 +298,7 @@ Parameters
298
298
  Optional, Ruby Exception object to log along with the duration of the supplied block
299
299
  ```
300
300
 
301
- #### Logging levels
301
+ ### Logging levels
302
302
 
303
303
  The following logging levels are available through Semantic Logger
304
304
 
@@ -317,7 +317,7 @@ in the development environment for low level trace logging of methods calls etc.
317
317
  If only the rails logger is being used, then :trace level calls will be logged
318
318
  as debug calls only if the log level is set to trace
319
319
 
320
- #### Changing the Class name for Log Entries
320
+ ### Changing the Class name for Log Entries
321
321
 
322
322
  When Semantic Logger is included in a Rails project it automatically replaces the
323
323
  loggers for Rails, ActiveRecord::Base, ActionController::Base, and ActiveResource::Base
@@ -356,7 +356,7 @@ This will result in the log output identifying the log entry as from the Externa
356
356
 
357
357
  2012-08-30 15:37:29.474 I [48308:ScriptThreadProcess: script/rails] (5.2ms) ExternalSupplier -- Calling external interface
358
358
 
359
- #### Tagged Logging
359
+ ### Tagged Logging
360
360
 
361
361
  Semantic Logger allows any Ruby or Rails program to also include tagged logging.
362
362
 
@@ -374,7 +374,7 @@ logger.tagged(tracking_number) do
374
374
  end
375
375
  ```
376
376
 
377
- #### Beyond Tagged Logging
377
+ ### Beyond Tagged Logging
378
378
 
379
379
  Blocks of code can be tagged with not only values, but can be tagged with
380
380
  entire hashes of data. The additional hash of data will be merged into
@@ -390,7 +390,7 @@ logger.with_payload(:user => 'Jack', :zip_code => 12345) do
390
390
  end
391
391
  ```
392
392
 
393
- #### Installation
393
+ ### Installation
394
394
 
395
395
  Add the following line to Gemfile
396
396
 
@@ -405,7 +405,7 @@ Install required gems with bundler
405
405
  This will automatically replace the standard Rails logger with Semantic Logger
406
406
  which will write all log data to the configured Rails logger.
407
407
 
408
- #### Configuration
408
+ ### Configuration
409
409
 
410
410
  By default Semantic Logger will detect the log level from Rails. To set the
411
411
  log level explicitly, add the following line to
@@ -415,6 +415,8 @@ config/environments/production.rb inside the Application.configure block
415
415
  config.log_level = :trace
416
416
  ```
417
417
 
418
+ #### MongoDB logging
419
+
418
420
  To log to both the Rails log file and MongoDB add the following lines to
419
421
  config/environments/production.rb inside the Application.configure block
420
422
 
@@ -432,6 +434,24 @@ config.after_initialize do
432
434
  end
433
435
  ```
434
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
+
435
455
  If the Rails colorized logging is enabled, then the colorized formatter will be used
436
456
  by default. To disable colorized logging in both Rails and SemanticLogger:
437
457
 
@@ -439,39 +459,97 @@ by default. To disable colorized logging in both Rails and SemanticLogger:
439
459
  config.colorize_logging = false
440
460
  ```
441
461
 
442
- ### Custom Appenders and Formatters
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
+ ```
443
483
 
444
- To write your own appenders or formatting, see [SemanticLogger](http://github.com/ClarityServices/semantic_logger)
484
+ To write your own appenders or formatting, see [SemanticLogger](http://github.com/reidmorrison/semantic_logger)
445
485
 
446
- ### Log Rotation
486
+ ## Log Rotation
447
487
 
448
488
  Since the log file is not re-opened with every call, when the log file needs
449
489
  to be rotated, use a copy-truncate operation rather than deleting the file.
450
490
 
451
- ### Dependencies
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
512
+
513
+ If running Puma 2 in Clustered mode and you're preloading your application,
514
+ add the following to your worker boot code:
515
+
516
+ ```ruby
517
+ # config/puma.rb
518
+ on_worker_boot do
519
+ # Re-open appenders after forking the process
520
+ SemanticLogger.reopen
521
+ end
522
+ ```
523
+
524
+ ## Dependencies
452
525
 
453
- - Ruby MRI 1.8.7, 1.9.3 (or above) Or, JRuby 1.6.3 (or above)
526
+ - Ruby MRI 1.8.7, 1.9.3, 2.0 (or above) Or, JRuby 1.6.3 (or above)
454
527
  - Rails 2, 3, 4 or above
455
528
 
456
529
  Meta
457
530
  ----
458
531
 
459
- * Code: `git clone git://github.com/ClarityServices/rails_semantic_logger.git`
460
- * Home: <https://github.com/ClarityServices/rails_semantic_logger>
461
- * Bugs: <http://github.com/ClarityServices/rails_semantic_logger/issues>
532
+ * Code: `git clone git://github.com/reidmorrison/rails_semantic_logger.git`
533
+ * Home: <https://github.com/reidmorrison/rails_semantic_logger>
534
+ * Bugs: <http://github.com/reidmorrison/rails_semantic_logger/issues>
462
535
  * Gems: <http://rubygems.org/gems/rails_semantic_logger>
463
536
 
464
537
  This project uses [Semantic Versioning](http://semver.org/).
465
538
 
466
- Authors
467
- -------
539
+ Author
540
+ ------
468
541
 
469
542
  Reid Morrison :: reidmo@gmail.com :: @reidmorrison
470
543
 
544
+ Contributors
545
+ ------------
546
+
547
+ Marc Bellingrath :: marrrc.b@gmail.com
548
+
471
549
  License
472
550
  -------
473
551
 
474
- Copyright 2012 Clarity Services, Inc.
552
+ Copyright 2012, 2013, 2014 Reid Morrison
475
553
 
476
554
  Licensed under the Apache License, Version 2.0 (the "License");
477
555
  you may not use this file except in compliance with the License.
@@ -6,7 +6,7 @@ module RailsSemanticLogger #:nodoc:
6
6
  # Example: Add the MongoDB logging appender in the Rails environment
7
7
  # initializer in file config/environments/development.rb
8
8
  #
9
- # Claritybase::Application.configure do
9
+ # Rails::Application.configure do
10
10
  # # Add the MongoDB logger appender only once Rails is initialized
11
11
  # config.after_initialize do
12
12
  # config.semantic_logger.add_appender SemanticLogger::Appender::Mongo.new(
@@ -70,5 +70,28 @@ module RailsSemanticLogger #:nodoc:
70
70
  ActiveSupport.on_load(:action_mailer) { self.logger = SemanticLogger['ActionMailer'] }
71
71
  end
72
72
 
73
+ # Support fork frameworks
74
+ config.after_initialize do
75
+ # Passenger provides the :starting_worker_process event for executing
76
+ # code after it has forked, so we use that and reconnect immediately.
77
+ if defined?(PhusionPassenger)
78
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
79
+ ::SemanticLogger.reopen if forked
80
+ end
81
+ end
82
+
83
+ # Re-open appenders after Resque has forked a worker
84
+ if defined?(Resque)
85
+ Resque.after_fork { |job| ::SemanticLogger.reopen }
86
+ end
87
+ end
88
+
89
+ # Before any initializers run
90
+ config.before_initialize do
91
+ # Replace the Mongoid Loggers after the gems have been loaded
92
+ Mongoid.logger = SemanticLogger[Mongoid] if defined?(Mongoid)
93
+ Moped.logger = SemanticLogger[Moped] if defined?(Moped)
94
+ end
95
+
73
96
  end
74
97
  end
@@ -1,3 +1,3 @@
1
1
  module RailsSemanticLogger #:nodoc
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.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-09-24 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic_logger
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.1
19
+ version: 2.5.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.3.1
26
+ version: 2.5.0
27
27
  description: Replaces the default Rails logger with SemanticLogger
28
28
  email:
29
29
  - reidmo@gmail.com
@@ -31,13 +31,13 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - lib/rails_semantic_logger/railtie.rb
35
- - lib/rails_semantic_logger/version.rb
36
- - lib/rails_semantic_logger.rb
37
34
  - LICENSE.txt
38
- - Rakefile
39
35
  - README.md
40
- homepage: https://github.com/ClarityServices/rails_semantic_logger
36
+ - Rakefile
37
+ - lib/rails_semantic_logger.rb
38
+ - lib/rails_semantic_logger/railtie.rb
39
+ - lib/rails_semantic_logger/version.rb
40
+ homepage: https://github.com/reidmorrison/rails_semantic_logger
41
41
  licenses:
42
42
  - Apache License V2.0
43
43
  metadata: {}
@@ -47,17 +47,17 @@ require_paths:
47
47
  - lib
48
48
  required_ruby_version: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - '>='
50
+ - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - '>='
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
59
  rubyforge_project:
60
- rubygems_version: 2.0.3
60
+ rubygems_version: 2.2.0
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Improved logging for Ruby on Rails