logging-rails 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.3.0 / 2011-09-19
2
+
3
+ Enhancements
4
+ - Appending default "log_to" destinations to the configuration files
5
+ - Remove the LogTail middleware if present
6
+ - Removing the Rails version check
7
+
1
8
  == 0.2.0 / 2011-09-16
2
9
 
3
10
  Enhancements
data/README.md CHANGED
@@ -7,18 +7,24 @@ framework into your Rails 3 application.
7
7
  Features
8
8
  --------
9
9
 
10
+ The railtie provides only one feature - integration of the **Logging**
11
+ framework into your Rails appcliation. But this gives you quite a bit of
12
+ flexibility to format your log messages and direct them to multiple logging
13
+ destiations: stdout with colors, a rolling log file, email, or even get a
14
+ growl notification.
15
+
10
16
  Install
11
17
  -------
12
18
 
13
- Add the ```logging-rails``` railtie gem to your rails project's Gemfile and run ```bundle install```.
19
+ Add the ```logging-rails``` railtie gem to your Rails project's Gemfile and run ```bundle install```.
14
20
 
15
21
  ```ruby
16
22
  gem 'logging-rails', :require => 'logging/rails'
17
23
  ````
18
24
 
19
25
  A generator is included with the railtie that will create a ```config/logging.rb```
20
- configuration file for use in your rails project. Please run this generator
21
- before attempting use the logging framework.
26
+ configuration file for use in your Rails project. Please run this generator
27
+ before attempting to use the **Logging** framework.
22
28
 
23
29
  ```
24
30
  rails generate logging:install
@@ -27,14 +33,58 @@ rails generate logging:install
27
33
  Usage
28
34
  -----
29
35
 
30
- Out of the box, the Logging framework is configured to behave in the same way
31
- as the standard Rails logger setup. The major exception is that the log file
32
- will be rolled daily - gone are the days of 2GB log files on production
36
+ Out of the box, the **Logging** framework is configured to behave in the same
37
+ way as the standard Rails logger setup. The major exception is that the log
38
+ file will be rolled daily - gone are the days of 2GB log files on production
33
39
  servers.
34
40
 
35
- config.log_to
41
+ The railtie adds a configuration option, ```log_to```, that determines where
42
+ log messages will be sent. This is an array of appender names (an appender
43
+ writes log messages to some destination such as a file, STDOUT, syslog, email,
44
+ etc.). The appender configuration should be set in your environment specific
45
+ configuration file. For example, in production we would want to log to a file
46
+ and send emails on error:
47
+
48
+ ```ruby
49
+ config.log_to = %w[file email]
50
+ ```
51
+
52
+ The **Logging** framework sets the global log level from the ```log_level```
53
+ configuration item. However, each class can be assigned its own log level.
54
+ This is very useful when debugging a single controller or model in your
55
+ Rails application. Consider the example below. The overall log level for the
56
+ application is set to ```:info```, but the log level for the *User* model and
57
+ controller is set to ```:debug```.
58
+
59
+ ```ruby
60
+ config.log_level = :info
61
+ Logging.logger['User'].level = :debug
62
+ Logging.logger['UserController'].level = :debug
63
+ ```
36
64
 
37
- Logging.logger['ModelName'].level = :debug
65
+ When using the logging railtie, a small display of the current logging
66
+ configuration will be displayed when the Rails logger is in the debug mode.
67
+ A description of the display can be found [here](https://github.com/TwP/logging/blob/master/lib/logging.rb#L400).
68
+
69
+ ```
70
+ root ............................................ *debug -T
71
+ - <Appenders::Stdout:0x806bc058 name="stdout">
72
+ - <Appenders::RollingFile:0x806bbc0c name="file">
73
+ ActionController::Base ........................ debug +A -T
74
+ ActiveRecord::Base ............................ debug +A -T
75
+ ActiveSupport::Cache::FileStore ............... debug +A -T
76
+ ActiveSupport::Dependencies ................... debug +A -T
77
+ Logging ....................................... *off -A -T
78
+ Rails ......................................... debug +A -T
79
+ ```
80
+
81
+ This is useful for understanding more complex logging configurations. It can
82
+ be annoying in day-to-day usage. The soluation is to set the Rails logger to
83
+ ```:info``` or higher.
84
+
85
+ ```ruby
86
+ Logging.logger['Rails'].level = :info
87
+ ```
38
88
 
39
89
  Author
40
90
  ------
data/lib/logging/rails.rb CHANGED
@@ -2,6 +2,12 @@
2
2
  require 'logging'
3
3
  include Logging.globally
4
4
 
5
+ require 'rails' if !defined? Rails or Rails.version
6
+
7
+ if Rails.version < '3'
8
+ abort("The Logging Railtie only works with Rails 3 or higher - you are running Rails #{Rails.version}")
9
+ end
10
+
5
11
  module Logging::Rails
6
12
 
7
13
  # :stopdoc:
@@ -66,3 +72,20 @@ module Logging::Rails
66
72
 
67
73
  end # Logging::Rails
68
74
 
75
+
76
+ # Here we need to remove the Rails LogTailer from the list of middlewares. The
77
+ # Logging framework is fully capable of sending log events to multiple logging
78
+ # destinations.
79
+ #
80
+ module Rails
81
+ class Server < ::Rack::Server
82
+ def middleware_without_log_tailer
83
+ middlewares = middleware_with_log_tailer['anything']
84
+ middlewares.delete_if { |middleware| Rails::Rack::LogTailer == middleware.first }
85
+ Hash.new(middlewares)
86
+ end
87
+ alias :middleware_with_log_tailer :middleware
88
+ alias :middleware :middleware_without_log_tailer
89
+ end
90
+ end
91
+
@@ -6,3 +6,7 @@ Example:
6
6
 
7
7
  This will create:
8
8
  config/logging.rb
9
+
10
+ And it will append "log_to" destinations to:
11
+ config/environments/development.rb
12
+ config/environments/production.rb
@@ -8,6 +8,12 @@ module Logging::Rails
8
8
  def generate_config
9
9
  template 'logging.rb.erb', 'config/logging.rb'
10
10
  end
11
+
12
+ def insert_log_to_destinations
13
+ comment = "\n # Set the logging destination(s)\n %s\n"
14
+ insert_into_file 'config/environments/development.rb', comment % 'config.log_to = %w[stdout file]', :before => %r/^end\s*$/
15
+ insert_into_file 'config/environments/production.rb', comment % 'config.log_to = %w[file]', :before => %r/^end\s*$/
16
+ end
11
17
  end
12
18
  end
13
19
  end
@@ -1,12 +1,4 @@
1
1
 
2
- if !defined? Rails or Rails.version
3
- abort('The Logging Railtie only works in the context of a Rails application')
4
- end
5
-
6
- if Rails.version < '3'
7
- abort("The Logging Railtie only works with Rails 3 or higher - you are running Rails #{Rails.version}")
8
- end
9
-
10
2
  module Logging::Rails
11
3
 
12
4
  # The Railtie is used to inject the Logging framework into the Rails
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-16 00:00:00.000000000Z
12
+ date: 2011-09-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logging
16
- requirement: &2163091300 !ruby/object:Gem::Requirement
16
+ requirement: &2154977120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2163091300
24
+ version_requirements: *2154977120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bones
27
- requirement: &2163090480 !ruby/object:Gem::Requirement
27
+ requirement: &2154976480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 3.7.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2163090480
35
+ version_requirements: *2154976480
36
36
  description: ! 'A Railtie for for integrating the [Logging](https://github.com/TwP/logging)
37
37
 
38
38
  framework into your Rails 3 application.'